Skip to content

Commit d3a3bc0

Browse files
committed
Add agno server
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: deecfab Pull-Request-resolved: #240
1 parent 9cf9d3f commit d3a3bc0

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

codemcp/agno.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import asyncio
2+
from typing import Union
3+
from urllib.parse import quote
4+
5+
from agno.agent import Agent
6+
from agno.api.playground import PlaygroundEndpointCreate, create_playground_endpoint
7+
from agno.cli.console import console
8+
from agno.cli.settings import agno_cli_settings
9+
from agno.models.anthropic import Claude
10+
from agno.playground import Playground
11+
from agno.tools.mcp import MCPTools
12+
from agno.utils.log import logger
13+
from fastapi import FastAPI
14+
from rich import box
15+
from rich.panel import Panel
16+
17+
18+
async def serve_playground_app_async(
19+
app: Union[str, FastAPI],
20+
*,
21+
scheme: str = "http",
22+
host: str = "localhost",
23+
port: int = 7777,
24+
reload: bool = False,
25+
prefix="/v1",
26+
**kwargs,
27+
):
28+
import uvicorn
29+
30+
try:
31+
create_playground_endpoint(
32+
playground=PlaygroundEndpointCreate(
33+
endpoint=f"{scheme}://{host}:{port}", playground_data={"prefix": prefix}
34+
),
35+
)
36+
except Exception as e:
37+
logger.error(f"Could not create playground endpoint: {e}")
38+
logger.error("Please try again.")
39+
return
40+
41+
logger.info(f"Starting playground on {scheme}://{host}:{port}")
42+
# Encode the full endpoint (host:port)
43+
encoded_endpoint = quote(f"{host}:{port}")
44+
45+
# Create a panel with the playground URL
46+
url = f"{agno_cli_settings.playground_url}?endpoint={encoded_endpoint}"
47+
panel = Panel(
48+
f"[bold green]Playground URL:[/bold green] [link={url}]{url}[/link]",
49+
title="Agent Playground",
50+
expand=False,
51+
border_style="cyan",
52+
box=box.HEAVY,
53+
padding=(2, 2),
54+
)
55+
56+
# Print the panel
57+
console.print(panel)
58+
59+
config = uvicorn.Config(app=app, host=host, port=port, reload=reload, **kwargs)
60+
server = uvicorn.Server(config)
61+
await server.serve()
62+
63+
64+
async def main():
65+
async with MCPTools(
66+
f"{sys.executable()} -m codemcp.hot_reload_entry"
67+
) as codemcp:
68+
# TODO: cli-ify the model
69+
agent = Agent(
70+
model=Claude(id="claude-3-7-sonnet-20250219"),
71+
tools=[codemcp],
72+
instructions="",
73+
markdown=True,
74+
show_tool_calls=True,
75+
)
76+
playground = Playground(agents=[agent]).get_app()
77+
await serve_playground_app_async(playground)
78+
79+
80+
if __name__ == "__main__":
81+
asyncio.run(main())

0 commit comments

Comments
 (0)