agno agentos 简单说明

agno agentos 实际上就是将agent,team,workflow,scheduler,直接暴露为可以提供服务访问的能力,内部基于了fastapi 进行的包装,同时提供了基于rbac的能力,agno 的一些remote 能力,也是基于此的(remote agent,remote team,remote workflow)

agentos 启动

from agno.os import AgentOS

agent_os = AgentOS(
    name="My AgentOS",
    agents=[my_agent],
    teams=[my_team],
    workflows=[my_workflow],
    tracing=True
)

app = agent_os.get_app()

if __name__ == "__main__":
    agent_os.serve(app="my_os:app", reload=True)

扩展路由

因为是基于了fast API 可以灵活扩展

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.anthropic import Claude
from agno.os import AgentOS
from agno.tools.hackernews import HackerNewsTools
from fastapi import FastAPI

# Create custom FastAPI app
app: FastAPI = FastAPI(
    title="Custom FastAPI App",
    version="1.0.0",
)


# Custom landing page (conflicts with AgentOS home route)
@app.get("/")
async def get_custom_home():
    return {
        "message": "Custom FastAPI App",
        "note": "Using on_route_conflict=\"preserve_base_app\" to preserve custom routes",
    }


# Custom health endpoint (conflicts with AgentOS health route)
@app.get("/health")
async def get_custom_health():
    return {"status": "custom_ok", "note": "This is your custom health endpoint"}


# Set up the AgentOS app by passing your FastAPI app
# Use on_route_conflict="preserve_base_app" to preserve your custom routes over AgentOS routes
agent_os = AgentOS(
    description="Example app with route replacement",
    agents=[web_research_agent],
    base_app=app,
    on_route_conflict="preserve_base_app",  # Skip conflicting AgentOS routes, keep your custom routes
)

app = agent_os.get_app()

暴露mcp服务

agent_os = AgentOS(
    description="Example app with MCP enabled",
    agents=[web_research_agent],
    enable_mcp_server=True,  # This enables a LLM-friendly MCP server at /mcp
)

动态agent 能力

通过factory 可以进行扩展

def build_tenant_agent(ctx: RequestContext) -> Agent:
    user_id = ctx.user_id or "anonymous"
    return Agent(
        model=OpenAIResponses(id="gpt-5.4"),
        db=db,
        instructions=f"You are a helpful assistant for tenant {user_id}. Be concise.",
        markdown=True,
    )


tenant_factory = AgentFactory(
    id="tenant-agent",
    db=db,
    factory=build_tenant_agent,
    name="Per-tenant assistant",
    description="Builds a personalized agent per tenant on each request.",
)

agent_os = AgentOS(agents=[tenant_factory])
app = agent_os.get_app()

说明

agno 的agentos 是将agno 能力暴露服务的一个能力,扩展点不少,是快速提供agent 能力一个不错的选择

参考资料

https://docs.agno.com/agent-os/run-your-os

posted on 2026-06-29 08:00  荣锋亮  阅读(6)  评论(0)    收藏  举报

导航