Hello,
I tried using built-in fastAPI following this sample
- I think there’s a typo here
fastapi_app = FastAPIApp(
agent=basic_agent,
name="Basic Agent",
app_id="basic_agent",
description="A basic agent that can answer questions and help with tasks.",
)
where it should be agents=[basic_agent]
. cmiiw
- when I run the updated python script and call the API with either this
curl -X 'POST' \
'http://localhost:8119/runs?agent_id=basic_agent' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'message=who founded python?' \
-F 'stream=true'
or this
curl -X POST \
'http://localhost:8119/runs' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'agent_id=basic_agent' \
-F 'message=who founded python?' \
-F 'stream=true'
this is what I got
{
"detail": "Agent not found"
}
Did I miss something? Thanks!
Ok, after some trials end errors, this works
from agno.agent import Agent
from agno.app.fastapi.app import FastAPIApp
from agno.models.openai import OpenAIChat
from agno.models.openrouter import OpenRouter
from dotenv import load_dotenv
import asyncio
import os
# Load environment variables
load_dotenv()
basic_agent = Agent(
name="Basic Agent",
agent_id="basic_agents",
model=OpenRouter(
id="openai/gpt-4.1-mini",
api_key=os.getenv("OPENROUTER_API_KEY")), # Ensure OPENAI_API_KEY is set
add_history_to_messages=True,
num_history_responses=3,
add_datetime_to_instructions=True,
markdown=True,
)
# Async router by default (use_async=True)
fastapi_app = FastAPIApp(
agents=[basic_agent],
name="Basic Agent",
app_id="basic",
description="A basic agent that can answer questions and help with tasks.",
)
# ✅ Add this
print("Registered agents:")
for agent in fastapi_app.agents:
print(f" - {agent.name} (app_id: {agent.app_id}, agent_id: {agent.agent_id})")
app = fastapi_app.get_app()
# For synchronous router:
# app = fastapi_app.get_app(use_async=False)
if __name__ == "__main__":
fastapi_app.serve(app="agent_fastapi:app", port=8119, reload=True)
1 Like
Hey @eibednejo
We are glad to see that you resolved the issue. Please let us know if you still want our team inputs - Happy to tag in engineers.