-
Notifications
You must be signed in to change notification settings - Fork 1.3k
AttributeError: module 'planner_agent' has no attribute 'handoffs' #596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
question
Question about using the SDK
Comments
Can you please share a full stack trace and/or code to reproduce? Hard to say where the error is coming from |
This is my Manager: from agents import Runner, gen_trace_id, trace
from rich.console import Console
from app.agent.agents import planner_agent
from app.agent.models.models import TokenResearchPlan
from app.agent.utils.printer import Printer
class Manager:
"""A workflow manager agent that orchestrates the execution of AI agent workflows.
The Manager class serves as a central coordinator for managing and executing AI agent workflows.
It handles:
- Initializing and configuring agent instances
- Managing the flow of execution between different agents
- Coordinating handoffs between agents
- Tracking and maintaining workflow state
- Handling errors and exceptions during workflow execution
This allows for modular and composable AI workflows where multiple specialized agents can work
together to accomplish complex tasks.
"""
def __init__(self) -> None:
self.console = Console()
self.printer = Printer(self.console)
async def run(self, query: str) -> None:
trace_id = gen_trace_id()
with trace("Agent Dexx trace", trace_id=trace_id):
self.printer.update_item(
"trace_id",
f"View trace: https://platform.openai.com/traces/trace?trace_id={trace_id}",
is_done=True,
hide_checkmark=True,
)
self.printer.update_item(
"start", "Starting token research...", is_done=True
)
# 3 Steps:
# 3.1 Plan the research
research_plan = await self.__plan_research(query=query)
# 3.2 Fetch Data
# 3.3 Write Report
async def __plan_research(self, query: str):
# self.printer.update_item("planning", "Planning research...")
result = await Runner.run(planner_agent, f"Query: {query}")
self.printer.update_item("planning", "Planning research...", is_done=True)
self.printer.update_item(
"planning",
f"Will perform {len(result.final_output.searches)} data collection tasks",
is_done=True,
)
return result.final_output My Planner Agent from agents import Agent
from app.agent.models.models import TokenResearchPlan
from app.agent.utils.custom_agent_hooks import CustomAgentHooks
from app.config.agent_lore import MODEL, PLANNER_AGENT_INSTRUCTIONS, PLANNER_AGENT_NAME
PROMPT = (
"You are a financial research planner. Given a request for financial analysis, "
"produce a set of web searches to gather the context needed. Aim for recent "
"headlines, earnings calls or 10‑K snippets, analyst commentary, and industry background. "
"Output between 5 and 15 search terms to query for."
)
planner_agent = Agent(
name=PLANNER_AGENT_NAME,
instructions=PROMPT,
model=MODEL,
) I am calling the manager from an REST endpoint: from fastapi import APIRouter
from app.models.prompt_request import PromptRequest
from app.agent.manager import Manager
router = APIRouter()
@router.post("/query")
async def query(request: PromptRequest):
manager = Manager()
await manager.run(request.prompt) Error Stacktrace: 2025-04-25 21:18:53,356 - app.main - INFO - 🚀 Server initialization in progress...
2025-04-25 21:18:53,356 - app.main - INFO - main.py:35 - 🚀 Server initialization in progress...
INFO: Started server process [11063]
INFO: Waiting for application startup.
INFO: Application startup complete.
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
return await self.app(scope, receive, send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 187, in __call__
raise exc
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 165, in __call__
await self.app(scope, receive, _send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/middleware/cors.py", line 85, in __call__
await self.app(scope, receive, send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 714, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 734, in app
await route.handle(scope, receive, send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
await self.app(scope, receive, send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 76, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 73, in app
response = await f(request)
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/fastapi/routing.py", line 301, in app
raw_response = await run_endpoint_function(
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
return await dependant.call(**values)
File "/home/harsh/git/aarkus/backend/token-insights-server/app/api/routes/query.py", line 11, in query
await manager.run(request.prompt)
File "/home/harsh/git/aarkus/backend/token-insights-server/app/agent/manager.py", line 54, in run
research_plan = await self.__plan_research(query=query)
File "/home/harsh/git/aarkus/backend/token-insights-server/app/agent/manager.py", line 60, in __plan_research
result = await Runner.run(planner_agent, f"Query: {query}")
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/agents/run.py", line 186, in run
handoff_names = [h.agent_name for h in cls._get_handoffs(current_agent)]
File "/home/harsh/.cache/pypoetry/virtualenvs/token-insights-server-htZV3EOI-py3.10/lib/python3.10/site-packages/agents/run.py", line 945, in _get_handoffs
for handoff_item in agent.handoffs:
AttributeError: module 'app.agent.agents.planner_agent' has no attribute 'handoffs'
2025-04-25 21:18:58,820 - httpx - INFO - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content"
2025-04-25 21:18:58,820 - httpx - INFO - _client.py:1025 - HTTP Request: POST https://api.openai.com/v1/traces/ingest "HTTP/1.1 204 No Content" Any help will be greateful |
I found my issue. It was the way I was importing my planner_agent. Instead of from app.agent.agents.planner_agent import planner_agent I was doing from app.agent.agents import planner_agent Closing this issue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Question
I am trying to recreate the financial_research_agent on my own. However when I define the planner agent as below:
I am getting the following error:
AttributeError: module 'app.agent.agents.planner_agent' has no attribute 'handoffs'
Why is the SDK expecting handoffs attribute when the instructions does not ask it to handoff?
Any help is appreciated. Thanks
The text was updated successfully, but these errors were encountered: