Skip to content

v0.70.0 - Experimental AI Features (agents and mcp server)

Latest
Compare
Choose a tag to compare
@sansyrox sansyrox released this 25 Jun 10:11

What's Changed

Full write up https://sanskar.wtf/posts/the-future-of-robyn

Experimental AI Features

First web framework with built-in AI agents and memory.

from robyn import Robyn
from robyn.ai import agent, memory

app = Robyn(__file__)

@app.post("/chat")
async def chat(request):
    mem = memory(provider="inmemory", user_id="user")
    ai_agent = agent(runner="simple", memory=mem)

    result = await ai_agent.run(request.json().get("query"))
    return {"response": result["response"]}

MCP Support

Native Model Context Protocol integration.

# MCP Resources
@app.mcp.resource("time://current")
def current_time() -> str:
    return f"Current time: {datetime.now().isoformat()}"


@app.mcp.tool(
    name="echo",
    description="Echo back text",
    input_schema={"type": "object", "properties": {"text": {"type": "string", "description": "Text to echo"}}, "required": ["text"]},
)
def echo_tool(args):
    return args.get("text", "")


# MCP Prompts
@app.mcp.prompt(
    name="explain_code",
    description="Generate code explanation prompt",
    arguments=[
        {"name": "code", "description": "Code to explain", "required": True},
        {"name": "language", "description": "Programming language", "required": False},
    ],
)
def explain_code_prompt(args):
    code = args.get("code", "")
    language = args.get("language", "unknown")

    return f"""Please explain this {language} code:

{language}
{code}
Include:
1. What it does
2. How it works
3. Key concepts used
"""

Note

These features are very much experimental. Checkout the examples/ folder to see the new features in action.

Install: pip install robyn==0.70.0

Full Changelog: v0.69.0...v0.70.0