Skip to content

Commit 8830d6f

Browse files
authored
Merge pull request #18 from moonpyt/doc-agents-clean
docs: update agent doc
2 parents 12c7516 + 628f964 commit 8830d6f

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

docs/core-concepts/agents.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,33 @@ response = await agent.run("Search Bitcoin price and calculate 10% of it")
136136

137137
Graph agents execute structured workflows defined as state graphs, supporting conditional branching, parallel execution, and complex multi-step pipelines.
138138

139-
```python
140-
from spoon_ai.agents import GraphAgent
141-
from spoon_ai.graph import StateGraph
139+
**Basic Usage:**
140+
141+
from spoon_ai.graph import StateGraph, START, END, GraphAgent
142142

143-
# Build workflow (see Graph System docs for StateGraph details)
143+
# Build workflow
144144
graph = StateGraph(MyState)
145-
graph.add_node("analyze", analyze_fn)
146-
graph.add_node("execute", execute_fn)
145+
graph.add_node("analyze", analyze_fn) # Node function
146+
graph.add_node("execute", execute_fn) # Node function
147147
graph.set_entry_point("analyze")
148-
graph.add_conditional_edge("analyze", router_fn)
148+
graph.add_conditional_edges("analyze", router_fn, {
149+
"execute": "execute",
150+
"skip": "skip_execution"
151+
})
149152

150-
# Agent with memory persistence
153+
# Create agent
151154
agent = GraphAgent(
152-
graph=graph.compile(),
153-
memory_path="./agent_memory",
154-
session_id="user_123"
155+
name="market_agent",
156+
graph=graph
155157
)
156158

157159
result = await agent.run("Analyze market and execute trades")
160+
**Node Functions:**
161+
- `analyze_fn(state)`: Receives current state, returns updated state dict
162+
- `execute_fn(state)`: Receives state with analysis results, returns execution results
163+
- `router_fn(state)`: Returns next node name as string for conditional routing
164+
165+
> 📖 **See complete example:** [`examples/intent_graph_demo.py`](https://github.com/XSpoonAi/spoon-core/blob/main/examples/intent_graph_demo.py) for full implementation including state schema, node functions, and error handling.
158166
```
159167
160168
**Best for:** Multi-step workflows, conditional logic, parallel tasks, human-in-the-loop.
@@ -207,13 +215,16 @@ class CustomAgent(BaseAgent):
207215

208216
```python
209217
import os
218+
import asyncio
219+
from dotenv import load_dotenv
210220
from spoon_ai.agents.spoon_react_mcp import SpoonReactMCP
211221
from spoon_ai.tools import ToolManager
212222
from spoon_ai.tools.mcp_tool import MCPTool
213223
from spoon_ai.chat import ChatBot
214224
from spoon_toolkits.crypto.crypto_powerdata.tools import CryptoPowerDataCEXTool
215225

216226
# Install extra dependency: pip install spoon-toolkits
227+
load_dotenv()
217228

218229
class SpoonMacroAnalysisAgent(SpoonReactMCP):
219230
name: str = "SpoonMacroAnalysisAgent"
@@ -240,11 +251,32 @@ class SpoonMacroAnalysisAgent(SpoonReactMCP):
240251
"env": {"TAVILY_API_KEY": tavily_key},
241252
},
242253
)
254+
255+
# Pre-load MCP tool parameters
256+
await tavily_tool.ensure_parameters_loaded()
243257

244258
crypto_tool = CryptoPowerDataCEXTool()
245259
self.available_tools = ToolManager([tavily_tool, crypto_tool])
246260

247-
agent = SpoonMacroAnalysisAgent(llm=ChatBot(llm_provider="openai"))
261+
262+
async def main():
263+
print("--- SpoonOS Macro Analysis Agent Demo ---")
264+
agent = SpoonMacroAnalysisAgent(
265+
llm=ChatBot(llm_provider="gemini", model_name="gemini-2.5-flash")
266+
)
267+
await agent.initialize()
268+
269+
query = (
270+
"Perform a macro analysis of Bitcoin (BTC). "
271+
"Search for recent news and get current market data from Binance using BTC/USDT pair."
272+
)
273+
print(f"\nRunning query: {query}")
274+
response = await agent.run(query)
275+
print(f"\n--- Analysis Complete ---\n{response}")
276+
277+
278+
if __name__ == "__main__":
279+
asyncio.run(main())
248280
```
249281

250282
## Best Practices

0 commit comments

Comments
 (0)