@@ -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
0 commit comments