@@ -83,14 +83,15 @@ result = agent("Analyze this repository for security issues")
8383### Custom Agent with Tools
8484
8585``` python
86+ import asyncio
87+ import dspy
8688from agenspy import BaseAgent
8789from typing import Dict, Any
8890
8991class CodeReviewAgent (BaseAgent ):
9092 def __init__ (self , name : str ):
9193 super ().__init__ (name)
92- self .register_tool(" review_code" , self .review_code)
93-
94+
9495 async def review_code (self , code : str , language : str ) -> Dict[str , Any]:
9596 """ Review code for potential issues."""
9697 # Your custom review logic here
@@ -99,10 +100,52 @@ class CodeReviewAgent(BaseAgent):
99100 " issues" : [" Consider adding error handling" , " Document this function" ],
100101 " suggestions" : [" Use list comprehension for better performance" ]
101102 }
103+
104+ async def forward (self , ** kwargs ) -> dspy.Prediction:
105+ """ Process agent request."""
106+ code = kwargs.get(" code" , " " )
107+ language = kwargs.get(" language" , " python" )
108+ result = await self .review_code(code, language)
109+ return dspy.Prediction(** result)
110+
111+ async def main ():
112+ # Configure DSPy with your preferred language model
113+ lm = dspy.LM(' openai/gpt-4o-mini' )
114+ dspy.configure(lm = lm)
115+
116+ # Create and use the agent
117+ agent = CodeReviewAgent(" code-reviewer" )
118+ result = await agent(code = " def add(a, b): return a + b" , language = " python" )
119+ print (" Review Results:" , result)
120+
121+ # Run the async main function
122+ if __name__ == " __main__" :
123+ asyncio.run(main())
124+ ```
125+
126+
127+ ### Python MCP Server
128+
129+ ``` python
130+
131+ from agentic_dspy.servers import GitHubMCPServer
132+
133+ # Create and start Python MCP server [header-11](#header-11)
134+ server = GitHubMCPServer(port = 8080 )
135+
136+ # Add custom tools [header-12](#header-12)
137+ async def custom_tool (param : str ):
138+ return f " Processed: { param} "
139+
140+ server.register_tool(
141+ " custom_tool" ,
142+ " A custom tool" ,
143+ {" param" : " string" },
144+ custom_tool
145+ )
146+
147+ server.start()
102148
103- # Usage
104- agent = CodeReviewAgent(" code-reviewer" )
105- result = await agent.review_code(" def add(a, b): return a + b" , " python" )
106149```
107150
108151# 🏗️ Architecture
@@ -140,59 +183,46 @@ Agenspy provides a protocol-first approach to building AI agents:
140183### Advanced Usage Example: Custom MCP Server
141184
142185``` python
143- from agenspy.servers import BaseMCPServer
186+ from agenspy.servers.mcp_python_server import PythonMCPServer
144187import asyncio
145188
146- class CustomMCPServer (BaseMCPServer ):
189+ class CustomMCPServer (PythonMCPServer ):
147190 def __init__ (self , port : int = 8080 ):
148- super ().__init__ (port = port)
149- self .register_tool(" custom_operation" , self .handle_custom_op)
150-
151- async def handle_custom_op (self , param1 : str , param2 : int ) -> dict :
191+ super ().__init__ (name = " custom-mcp-server" , port = port)
192+ self .register_tool(
193+ name = " custom_operation" ,
194+ description = " A custom operation that processes parameters" ,
195+ parameters = {
196+ " type" : " object" ,
197+ " properties" : {
198+ " param1" : {" type" : " string" , " description" : " First parameter" },
199+ " param2" : {" type" : " integer" , " description" : " Second parameter" }
200+ },
201+ " required" : [" param1" , " param2" ]
202+ },
203+ handler = self .handle_custom_op
204+ )
205+
206+ async def handle_custom_op (self , ** kwargs ):
152207 """ Handle custom operation with parameters."""
153- return {" result" : f " Processed { param1} with { param2} " }
208+ param1 = kwargs.get(" param1" )
209+ param2 = kwargs.get(" param2" )
210+ return f " Processed { param1} with { param2} "
154211
155212# Start the server
156- server = CustomMCPServer(port = 8080 )
157- print (" Starting MCP server on port 8080..." )
158- server.start()
213+ if __name__ == " __main__" :
214+ server = CustomMCPServer(port = 8080 )
215+ print (" Starting MCP server on port 8080..." )
216+ server.start()
159217```
160218
161219## 🖥️ Command Line Interface
162220
163221Agenspy provides a command-line interface for managing agents and protocols:
164222
165- ### Basic Commands
166223``` bash
167224# Show help and available commands
168225agenspy --help
169-
170- # Show version information
171- agenspy --version
172- ```
173-
174- ### Agent Management
175- ``` bash
176- # List available agents
177- agenspy agent --help
178- ```
179-
180- ### Protocol Management
181- ``` bash
182- # List available protocols
183- agenspy protocol --help
184-
185- # Test protocol connection
186- agenspy protocol test [PROTOCOL] [--server SERVER]
187-
188- # Get detailed information about a protocol
189- agenspy protocol info [PROTOCOL_NAME]
190- ```
191-
192- ### Server Management
193- ``` bash
194- # Start the server
195- agenspy server --help
196226```
197227
198228## 📚 Documentation
0 commit comments