Skip to content

Commit f861deb

Browse files
committed
2 parents dc83d07 + 5072334 commit f861deb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+25067
-4
lines changed

docs/api-reference/spoon_ai/agents/base.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,193 @@ title: spoon_ai.agents.base
66

77
# Table of Contents
88

9+
* [spoon\_ai.agents.base](#spoon_ai.agents.base)
10+
* [ThreadSafeOutputQueue](#spoon_ai.agents.base.ThreadSafeOutputQueue)
11+
* [get](#spoon_ai.agents.base.ThreadSafeOutputQueue.get)
12+
* [BaseAgent](#spoon_ai.agents.base.BaseAgent)
13+
* [add\_message](#spoon_ai.agents.base.BaseAgent.add_message)
14+
* [state\_context](#spoon_ai.agents.base.BaseAgent.state_context)
15+
* [run](#spoon_ai.agents.base.BaseAgent.run)
16+
* [step](#spoon_ai.agents.base.BaseAgent.step)
17+
* [is\_stuck](#spoon_ai.agents.base.BaseAgent.is_stuck)
18+
* [handle\_stuck\_state](#spoon_ai.agents.base.BaseAgent.handle_stuck_state)
19+
* [add\_documents](#spoon_ai.agents.base.BaseAgent.add_documents)
20+
* [save\_chat\_history](#spoon_ai.agents.base.BaseAgent.save_chat_history)
21+
* [stream](#spoon_ai.agents.base.BaseAgent.stream)
22+
* [process\_mcp\_message](#spoon_ai.agents.base.BaseAgent.process_mcp_message)
23+
* [shutdown](#spoon_ai.agents.base.BaseAgent.shutdown)
24+
* [get\_diagnostics](#spoon_ai.agents.base.BaseAgent.get_diagnostics)
25+
26+
<a id="spoon_ai.agents.base"></a>
27+
28+
# Module `spoon_ai.agents.base`
29+
30+
<a id="spoon_ai.agents.base.ThreadSafeOutputQueue"></a>
31+
32+
## `ThreadSafeOutputQueue` Objects
33+
34+
```python
35+
class ThreadSafeOutputQueue()
36+
```
37+
38+
Thread-safe output queue with fair access and timeout protection
39+
40+
<a id="spoon_ai.agents.base.ThreadSafeOutputQueue.get"></a>
41+
42+
#### `get`
43+
44+
```python
45+
async def get(timeout: Optional[float] = 30.0) -> Any
46+
```
47+
48+
Get item with timeout and fair access
49+
50+
<a id="spoon_ai.agents.base.BaseAgent"></a>
51+
52+
## `BaseAgent` Objects
53+
54+
```python
55+
class BaseAgent(BaseModel, ABC)
56+
```
57+
58+
Thread-safe base class for all agents with proper concurrency handling.
59+
60+
<a id="spoon_ai.agents.base.BaseAgent.add_message"></a>
61+
62+
#### `add_message`
63+
64+
```python
65+
async def add_message(role: Literal["user", "assistant", "tool"],
66+
content: str,
67+
tool_call_id: Optional[str] = None,
68+
tool_calls: Optional[List[ToolCall]] = None,
69+
tool_name: Optional[str] = None,
70+
timeout: Optional[float] = None) -> None
71+
```
72+
73+
Thread-safe message addition with timeout protection
74+
75+
<a id="spoon_ai.agents.base.BaseAgent.state_context"></a>
76+
77+
#### `state_context`
78+
79+
```python
80+
@asynccontextmanager
81+
async def state_context(new_state: AgentState,
82+
timeout: Optional[float] = None)
83+
```
84+
85+
Thread-safe state context manager with deadlock prevention.
86+
Acquires the state lock only to perform quick transitions, not for the
87+
duration of the work inside the context, avoiding long-held locks and
88+
false timeouts during network calls.
89+
90+
<a id="spoon_ai.agents.base.BaseAgent.run"></a>
91+
92+
#### `run`
93+
94+
```python
95+
async def run(request: Optional[str] = None,
96+
timeout: Optional[float] = None) -> str
97+
```
98+
99+
Thread-safe run method with proper concurrency control and callback support.
100+
101+
<a id="spoon_ai.agents.base.BaseAgent.step"></a>
102+
103+
#### `step`
104+
105+
```python
106+
async def step(run_id: Optional[uuid.UUID] = None) -> str
107+
```
108+
109+
Override this method in subclasses - now with step-level locking and callback support.
110+
111+
<a id="spoon_ai.agents.base.BaseAgent.is_stuck"></a>
112+
113+
#### `is_stuck`
114+
115+
```python
116+
async def is_stuck() -> bool
117+
```
118+
119+
Thread-safe stuck detection
120+
121+
<a id="spoon_ai.agents.base.BaseAgent.handle_stuck_state"></a>
122+
123+
#### `handle_stuck_state`
124+
125+
```python
126+
async def handle_stuck_state()
127+
```
128+
129+
Thread-safe stuck state handling
130+
131+
<a id="spoon_ai.agents.base.BaseAgent.add_documents"></a>
132+
133+
#### `add_documents`
134+
135+
```python
136+
def add_documents(documents) -> None
137+
```
138+
139+
Store documents on the agent so CLI load-docs works without RAG mixin.
140+
141+
This default implementation keeps the documents in-memory under
142+
self._loaded_documents. Agents that support retrieval should override
143+
this method to index documents into their vector store.
144+
145+
<a id="spoon_ai.agents.base.BaseAgent.save_chat_history"></a>
146+
147+
#### `save_chat_history`
148+
149+
```python
150+
def save_chat_history()
151+
```
152+
153+
Thread-safe chat history saving
154+
155+
<a id="spoon_ai.agents.base.BaseAgent.stream"></a>
156+
157+
#### `stream`
158+
159+
```python
160+
async def stream(timeout: Optional[float] = None)
161+
```
162+
163+
Thread-safe streaming with proper cleanup and timeout
164+
165+
<a id="spoon_ai.agents.base.BaseAgent.process_mcp_message"></a>
166+
167+
#### `process_mcp_message`
168+
169+
```python
170+
async def process_mcp_message(content: Any,
171+
sender: str,
172+
message: Dict[str, Any],
173+
agent_id: str,
174+
timeout: Optional[float] = None)
175+
```
176+
177+
Thread-safe MCP message processing with timeout protection
178+
179+
<a id="spoon_ai.agents.base.BaseAgent.shutdown"></a>
180+
181+
#### `shutdown`
182+
183+
```python
184+
async def shutdown(timeout: float = 30.0)
185+
```
186+
187+
Graceful shutdown with cleanup of active operations
188+
189+
<a id="spoon_ai.agents.base.BaseAgent.get_diagnostics"></a>
190+
191+
#### `get_diagnostics`
192+
193+
```python
194+
def get_diagnostics() -> Dict[str, Any]
195+
```
196+
197+
Get diagnostic information about the agent's state
9198

docs/api-reference/spoon_ai/agents/custom_agent.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,162 @@ title: spoon_ai.agents.custom_agent
66

77
# Table of Contents
88

9+
* [spoon\_ai.agents.custom\_agent](#spoon_ai.agents.custom_agent)
10+
* [CustomAgent](#spoon_ai.agents.custom_agent.CustomAgent)
11+
* [add\_tool](#spoon_ai.agents.custom_agent.CustomAgent.add_tool)
12+
* [add\_tools](#spoon_ai.agents.custom_agent.CustomAgent.add_tools)
13+
* [remove\_tool](#spoon_ai.agents.custom_agent.CustomAgent.remove_tool)
14+
* [list\_tools](#spoon_ai.agents.custom_agent.CustomAgent.list_tools)
15+
* [get\_tool\_info](#spoon_ai.agents.custom_agent.CustomAgent.get_tool_info)
16+
* [validate\_tools](#spoon_ai.agents.custom_agent.CustomAgent.validate_tools)
17+
* [run](#spoon_ai.agents.custom_agent.CustomAgent.run)
18+
* [clear](#spoon_ai.agents.custom_agent.CustomAgent.clear)
19+
20+
<a id="spoon_ai.agents.custom_agent"></a>
21+
22+
# Module `spoon_ai.agents.custom_agent`
23+
24+
<a id="spoon_ai.agents.custom_agent.CustomAgent"></a>
25+
26+
## `CustomAgent` Objects
27+
28+
```python
29+
class CustomAgent(ToolCallAgent)
30+
```
31+
32+
Custom Agent class allowing users to create their own agents and add custom tools
33+
34+
Usage:
35+
Create custom agent and add tools:
36+
agent = CustomAgent(name="my_agent", description="My custom agent")
37+
agent.add_tool(MyCustomTool())
38+
result = await agent.run("Use my custom tool")
39+
40+
<a id="spoon_ai.agents.custom_agent.CustomAgent.add_tool"></a>
41+
42+
#### `add_tool`
43+
44+
```python
45+
def add_tool(tool: BaseTool) -> None
46+
```
47+
48+
Add a tool to the agent with validation.
49+
50+
**Arguments**:
51+
52+
- `tool` - Tool instance to add
53+
54+
55+
**Raises**:
56+
57+
- `ValueError` - If tool is invalid or already exists
58+
59+
<a id="spoon_ai.agents.custom_agent.CustomAgent.add_tools"></a>
60+
61+
#### `add_tools`
62+
63+
```python
64+
def add_tools(tools: List[BaseTool]) -> None
65+
```
66+
67+
Add multiple tools to the agent with atomic operation.
68+
69+
**Arguments**:
70+
71+
- `tools` - List of tool instances to add
72+
73+
74+
**Raises**:
75+
76+
- `ValueError` - If any tool is invalid
77+
78+
<a id="spoon_ai.agents.custom_agent.CustomAgent.remove_tool"></a>
79+
80+
#### `remove_tool`
81+
82+
```python
83+
def remove_tool(tool_name: str) -> bool
84+
```
85+
86+
Remove a tool from the agent.
87+
88+
**Arguments**:
89+
90+
- `tool_name` - Name of the tool to remove
91+
92+
93+
**Returns**:
94+
95+
- `bool` - True if tool was removed, False if not found
96+
97+
<a id="spoon_ai.agents.custom_agent.CustomAgent.list_tools"></a>
98+
99+
#### `list_tools`
100+
101+
```python
102+
def list_tools() -> List[str]
103+
```
104+
105+
List all available tools in the agent.
106+
107+
**Returns**:
108+
109+
List of tool names, empty list if no tools
110+
111+
<a id="spoon_ai.agents.custom_agent.CustomAgent.get_tool_info"></a>
112+
113+
#### `get_tool_info`
114+
115+
```python
116+
def get_tool_info() -> Dict[str, Dict[str, Any]]
117+
```
118+
119+
Get detailed information about all tools.
120+
121+
**Returns**:
122+
123+
Dictionary with tool names as keys and tool info as values
124+
125+
<a id="spoon_ai.agents.custom_agent.CustomAgent.validate_tools"></a>
126+
127+
#### `validate_tools`
128+
129+
```python
130+
def validate_tools() -> Dict[str, Any]
131+
```
132+
133+
Validate all current tools and return validation report.
134+
135+
**Returns**:
136+
137+
Dictionary with validation results
138+
139+
<a id="spoon_ai.agents.custom_agent.CustomAgent.run"></a>
140+
141+
#### `run`
142+
143+
```python
144+
async def run(request: Optional[str] = None) -> str
145+
```
146+
147+
Run the agent with enhanced tool validation.
148+
149+
**Arguments**:
150+
151+
- `request` - User request
152+
153+
154+
**Returns**:
155+
156+
Processing result
157+
158+
<a id="spoon_ai.agents.custom_agent.CustomAgent.clear"></a>
159+
160+
#### `clear`
161+
162+
```python
163+
def clear()
164+
```
165+
166+
Enhanced clear method with proper tool state management.
9167

0 commit comments

Comments
 (0)