When running an AutoAgents hierarchical workflow in praisonaiagents, the process fails with a hard error if the OpenAI API key is not set, even when OpenAI is not being used as the LLM. The manager task attempts to create an OpenAI client and raises an error about missing credentials, which interrupts the workflow and prevents completion.
from praisonaiagents import AutoAgents
def get_stock_price(company_name: str) -> str:
"""
Get the stock price of a company
Args:
company_name (str): The name of the company
Returns:
str: The stock price of the company
"""
if company_name.lower() == "apple" or company_name.lower() == "aapl":
return f"The stock price of {company_name} is 100"
elif company_name.lower() == "google" or company_name.lower() == "googl":
return f"The stock price of {company_name} is 200"
else:
return f"The stock price of {company_name} is 50"
# Create AutoAgents instance
agents = AutoAgents(
instructions="Write a poem on the stock price of apple",
tools=[get_stock_price],
process="hierarchical",
llm="gemini/gemini-2.5-flash-lite-preview-06-17",
self_reflect=True,
verbose=True,
max_agents=3 # Maximum number of agents to create
)
# Start the agents
result = agents.start()
print(result)
The workflow should not require or attempt to use an OpenAI API key when OpenAI is not the selected LLM.
The manager task and the entire workflow should execute and complete successfully without any dependency on OpenAI credentials, unless explicitly configured to use OpenAI.
╭───────────── Tool Call ─────────────╮
│ 🛠️ Available Tools: get_stock_price │
╰─────────────────────────────────────╯
[01:00:16] INFO [01:00:16] llm.py:593 INFO Getting response from llm.py:593
gemini/gemini-2.5-flash-lite-preview-06-17
[01:00:22] WARNING [01:00:22] autoagents.py:405 WARNING Generated 2 agents, expected 3 autoagents.py:405
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ 👤 Agent: Stock Data Analyst │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
│ Role: Financial Data Analyst Goal: To gather and analyze recent Apple stock price data. Tools: │
│ get_stock_price │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ 👤 Agent: Poetry Generator │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
│ Role: Creative Poet Goal: To transform stock price data into a compelling poem. Tools: get_stock_price │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
INFO [01:00:22] llm.py:593 INFO Getting response from llm.py:593
gemini/gemini-2.5-flash-lite-preview-06-17
╭─ Agent Info ───────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ 👤 Agent: Manager │
│ Role: Project manager │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
/Users/mzaza/Documents/Practice
Projects/praison_demo/venv/lib/python3.11/site-packages/httpx/_models.py:408: DeprecationWarning: Use
'content=<...>' to upload raw bytes/text content.
headers, stream = encode_request(
/Users/mzaza/Documents/Practice
Projects/praison_demo/venv/lib/python3.11/site-packages/litellm/litellm_core_utils/streaming_handler.py:15
45: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in
Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at
https://errors.pydantic.dev/2.11/migration/
obj_dict = response.dict()
╭────────────────────────────────────────── Generating... 3.0s ──────────────────────────────────────────╮
│ │
│ 1 Agent: Research Agent │
│ • Task: Research the best practices for project management in a multi-agent system. │
│ • Sub-tasks: │
│ • Identify common challenges in coordinating multiple AI agents. │
│ • Explore different task delegation strategies. │
│ • Investigate communication protocols suitable for agent interaction. │
│ • Research methods for monitoring and evaluating agent performance. │
│ 2 Agent: Planning Agent │
│ • Task: Based on the research findings, develop a comprehensive project plan. │
│ • Sub-tasks: │
│ • Define the overall project objective and key performance indicators (KPIs). │
│ • Break down the project into smaller, manageable tasks. │
│ • Sequence the tasks logically, considering dependencies. │
│ • Assign specific tasks to appropriate agents (including itself and others). │
│ • Establish communication channels and reporting mechanisms between agents. │
│ • Define a timeline with milestones and deadlines. │
│ 3 Agent: Execution Agent (General Purpose) │
│ • Task: Execute assigned tasks according to the project plan. │
│ • Sub-tasks: │
│ • Receive task assignments from the Planning Agent. │
│ • Perform the assigned task. │
│ • Report completion status and any encountered issues to the Planning Agent. │
│ 4 Agent: Monitoring Agent │
│ • Task: Oversee the progress of all agents and ensure adherence to the project plan. │
│ • Sub-tasks: │
│ • Track the status of each task. │
│ • Identify any deviations from the plan or potential bottlenecks. │
│ • Report any critical issues or risks to the Planning Agent. │
│ • Provide feedback on agent performance. │
│ 5 Agent: Communication Agent │
│ • Task: Facilitate seamless communication between all agents. │
│ • Sub-tasks: │
│ • Relay messages and updates between agents. │
│ • Ensure clarity and conciseness in all communications. │
│ • Manage the flow of information according to defined protocols. │
│ 6 Agent: Reporting Agent │
│ • Task: Compile and present project status reports. │
│ • Sub-tasks: │
│ • Gather progress updates from the Monitoring Agent and Planning Agent. │
│ • Generate regular project status reports, highlighting achievements, challenges, and next │
│ steps. │
│ • Disseminate reports to relevant stakeholders (if applicable). │
│ │
│ Execution Flow: │
│ │
│ 1 Research Agent performs its research tasks. │
│ 2 Planning Agent receives the research output and develops the project plan. │
│ 3 Planning Agent assigns tasks to Execution Agent(s), Monitoring Agent, Communication Agent, and │
│ Reporting Agent. │
│ 4 Execution Agent(s) begin executing their assigned tasks, reporting back to the Planning Agent. │
│ 5 Monitoring Agent continuously tracks progress and reports to the Planning Agent. │
│ 6 Communication Agent facilitates all inter-agent communication. │
│ 7 Reporting Agent compiles and disseminates reports based on information from the Planning Agent and │
│ Monitoring Agent. │
│ 8 Planning Agent oversees the entire process, making adjustments as needed and ensuring all tasks are │
│ completed successfully. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Response generated in 3.0s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Decide the order of tasks and which agent executes them. Expected │
│ Output: All tasks completed successfully. Please provide only the final result of your work. Do not │
│ add any conversation or extra explanation. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
│ │
│ 1 Agent: Research Agent │
│ • Task: Research the best practices for project management in a multi-agent system. │
│ • Sub-tasks: │
│ • Identify common challenges in coordinating multiple AI agents. │
│ • Explore different task delegation strategies. │
│ • Investigate communication protocols suitable for agent interaction. │
│ • Research methods for monitoring and evaluating agent performance. │
│ 2 Agent: Planning Agent │
│ • Task: Based on the research findings, develop a comprehensive project plan. │
│ • Sub-tasks: │
│ • Define the overall project objective and key performance indicators (KPIs). │
│ • Break down the project into smaller, manageable tasks. │
│ • Sequence the tasks logically, considering dependencies. │
│ • Assign specific tasks to appropriate agents (including itself and others). │
│ • Establish communication channels and reporting mechanisms between agents. │
│ • Define a timeline with milestones and deadlines. │
│ 3 Agent: Execution Agent (General Purpose) │
│ • Task: Execute assigned tasks according to the project plan. │
│ • Sub-tasks: │
│ • Receive task assignments from the Planning Agent. │
│ • Perform the assigned task. │
│ • Report completion status and any encountered issues to the Planning Agent. │
│ 4 Agent: Monitoring Agent │
│ • Task: Oversee the progress of all agents and ensure adherence to the project plan. │
│ • Sub-tasks: │
│ • Track the status of each task. │
│ • Identify any deviations from the plan or potential bottlenecks. │
│ • Report any critical issues or risks to the Planning Agent. │
│ • Provide feedback on agent performance. │
│ 5 Agent: Communication Agent │
│ • Task: Facilitate seamless communication between all agents. │
│ • Sub-tasks: │
│ • Relay messages and updates between agents. │
│ • Ensure clarity and conciseness in all communications. │
│ • Manage the flow of information according to defined protocols. │
│ 6 Agent: Reporting Agent │
│ • Task: Compile and present project status reports. │
│ • Sub-tasks: │
│ • Gather progress updates from the Monitoring Agent and Planning Agent. │
│ • Generate regular project status reports, highlighting achievements, challenges, and next │
│ steps. │
│ • Disseminate reports to relevant stakeholders (if applicable). │
│ │
│ Execution Flow: │
│ │
│ 1 Research Agent performs its research tasks. │
│ 2 Planning Agent receives the research output and develops the project plan. │
│ 3 Planning Agent assigns tasks to Execution Agent(s), Monitoring Agent, Communication Agent, and │
│ Reporting Agent. │
│ 4 Execution Agent(s) begin executing their assigned tasks, reporting back to the Planning Agent. │
│ 5 Monitoring Agent continuously tracks progress and reports to the Planning Agent. │
│ 6 Communication Agent facilitates all inter-agent communication. │
│ 7 Reporting Agent compiles and disseminates reports based on information from the Planning Agent and │
│ Monitoring Agent. │
│ 8 Planning Agent oversees the entire process, making adjustments as needed and ensuring all tasks are │
│ completed successfully. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Response generated in 3.0s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Decide the order of tasks and which agent executes them. Expected │
│ Output: All tasks completed successfully. Please provide only the final result of your work. Do not │
│ add any conversation or extra explanation. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
│ │
│ 1 Agent: Research Agent │
│ • Task: Research the best practices for project management in a multi-agent system. │
│ • Sub-tasks: │
│ • Identify common challenges in coordinating multiple AI agents. │
│ • Explore different task delegation strategies. │
│ • Investigate communication protocols suitable for agent interaction. │
│ • Research methods for monitoring and evaluating agent performance. │
│ 2 Agent: Planning Agent │
│ • Task: Based on the research findings, develop a comprehensive project plan. │
│ • Sub-tasks: │
│ • Define the overall project objective and key performance indicators (KPIs). │
│ • Break down the project into smaller, manageable tasks. │
│ • Sequence the tasks logically, considering dependencies. │
│ • Assign specific tasks to appropriate agents (including itself and others). │
│ • Establish communication channels and reporting mechanisms between agents. │
│ • Define a timeline with milestones and deadlines. │
│ 3 Agent: Execution Agent (General Purpose) │
│ • Task: Execute assigned tasks according to the project plan. │
│ • Sub-tasks: │
│ • Receive task assignments from the Planning Agent. │
│ • Perform the assigned task. │
│ • Report completion status and any encountered issues to the Planning Agent. │
│ 4 Agent: Monitoring Agent │
│ • Task: Oversee the progress of all agents and ensure adherence to the project plan. │
│ • Sub-tasks: │
│ • Track the status of each task. │
│ • Identify any deviations from the plan or potential bottlenecks. │
│ • Report any critical issues or risks to the Planning Agent. │
│ • Provide feedback on agent performance. │
│ 5 Agent: Communication Agent │
│ • Task: Facilitate seamless communication between all agents. │
│ • Sub-tasks: │
│ • Relay messages and updates between agents. │
│ • Ensure clarity and conciseness in all communications. │
│ • Manage the flow of information according to defined protocols. │
│ 6 Agent: Reporting Agent │
│ • Task: Compile and present project status reports. │
│ • Sub-tasks: │
│ • Gather progress updates from the Monitoring Agent and Planning Agent. │
│ • Generate regular project status reports, highlighting achievements, challenges, and next │
│ steps. │
│ • Disseminate reports to relevant stakeholders (if applicable). │
│ │
│ Execution Flow: │
│ │
│ 1 Research Agent performs its research tasks. │
│ 2 Planning Agent receives the research output and develops the project plan. │
│ 3 Planning Agent assigns tasks to Execution Agent(s), Monitoring Agent, Communication Agent, and │
│ Reporting Agent. │
│ 4 Execution Agent(s) begin executing their assigned tasks, reporting back to the Planning Agent. │
│ 5 Monitoring Agent continuously tracks progress and reports to the Planning Agent. │
│ 6 Communication Agent facilitates all inter-agent communication. │
│ 7 Reporting Agent compiles and disseminates reports based on information from the Planning Agent and │
│ Monitoring Agent. │
│ 8 Planning Agent oversees the entire process, making adjustments as needed and ensuring all tasks are │
│ completed successfully. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
[01:00:25] INFO [01:00:25] process.py:1280 INFO Created manager task with ID None process.py:1280
INFO [01:00:25] process.py:1284 INFO Need to complete 2 tasks (excluding process.py:1284
manager task)
INFO [01:00:25] process.py:1299 INFO Task 0 status: {'task_id': 0, 'name': process.py:1299
'Fetch Apple Stock Data', 'description': 'Retrieve the historical
stock price data for Apple (AAPL) for the past year.', 'status': 'not
started', 'agent': 'Stock Data Analyst'}
INFO [01:00:25] process.py:1299 INFO Task 1 status: {'task_id': 1, 'name': process.py:1299
'Compose Stock Poem', 'description': "Write a poem that reflects the
trends, highs, and lows of Apple's stock price over the past year,
using the provided data.", 'status': 'not started', 'agent': 'Poetry
Generator'}
INFO [01:00:25] process.py:1314 INFO Requesting manager instructions... process.py:1314
╭──────────────────────────────────────────────── Error ─────────────────────────────────────────────────╮
│ Manager parse error: The api_key client option must be set either by passing api_key to the client or │
│ by setting the OPENAI_API_KEY environment variable │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ERROR [01:00:25] process.py:1321 ERROR Manager parse error: The api_key process.py:1321
client option must be set either by passing api_key to the client or
by setting the OPENAI_API_KEY environment variable
╭──────────────── Traceback (most recent call last) ─────────────────╮
│ /Users/mzaza/Documents/Practice │
│ Projects/praison_demo/venv/lib/python3.11/site-packages/praisonaia │
│ gents/process/process.py:1315 in hierarchical │
│ │
│ 1312 │ │ │ │
│ 1313 │ │ │ try: │
│ 1314 │ │ │ │ logging.info("Requesting manager instructio │
│ ❱ 1315 │ │ │ │ parsed_instructions = self._get_manager_ins │
│ 1316 │ │ │ │ │ manager_task, manager_prompt, ManagerIn │
│ 1317 │ │ │ │ ) │
│ 1318 │ │ │ │ logging.info(f"Manager instructions: {parse │
│ │
│ /Users/mzaza/Documents/Practice │
│ Projects/praison_demo/venv/lib/python3.11/site-packages/praisonaia │
│ gents/process/process.py:171 in │
│ _get_manager_instructions_with_fallback │
│ │
│ 168 │ def _get_manager_instructions_with_fallback(self, manag │
│ ManagerInstructions): │
│ 169 │ │ """Sync version of getting manager instructions wit │
│ 170 │ │ # Create OpenAI client │
│ ❱ 171 │ │ client = OpenAI() │
│ 172 │ │ try: │
│ 173 │ │ │ # First try structured output (OpenAI compatibl │
│ 174 │ │ │ logging.info("Attempting structured output...") │
│ │
│ /Users/mzaza/Documents/Practice │
│ Projects/praison_demo/venv/lib/python3.11/site-packages/openai/_cl │
│ ient.py:130 in __init__ │
│ │
│ 127 │ │ if api_key is None: │
│ 128 │ │ │ api_key = os.environ.get("OPENAI_API_KEY") │
│ 129 │ │ if api_key is None: │
│ ❱ 130 │ │ │ raise OpenAIError( │
│ 131 │ │ │ │ "The api_key client option must be set eith │
│ client or by setting the OPENAI_API_KEY environment variabl │
│ 132 │ │ │ ) │
│ 133 │ │ self.api_key = api_key │
╰────────────────────────────────────────────────────────────────────╯
OpenAIError: The api_key client option must be set either by passing
api_key to the client or by setting the OPENAI_API_KEY environment
variable
INFO [01:00:25] process.py:1358 INFO All tasks completed under manager process.py:1358
supervision.
INFO [01:00:25] process.py:1359 INFO Hierarchical task execution finished process.py:1359
1. **Agent: Research Agent**
- **Task:** Research the best practices for project management in a multi-agent system.
- **Sub-tasks:**
- Identify common challenges in coordinating multiple AI agents.
- Explore different task delegation strategies.
- Investigate communication protocols suitable for agent interaction.
- Research methods for monitoring and evaluating agent performance.
2. **Agent: Planning Agent**
- **Task:** Based on the research findings, develop a comprehensive project plan.
- **Sub-tasks:**
- Define the overall project objective and key performance indicators (KPIs).
- Break down the project into smaller, manageable tasks.
- Sequence the tasks logically, considering dependencies.
- Assign specific tasks to appropriate agents (including itself and others).
- Establish communication channels and reporting mechanisms between agents.
- Define a timeline with milestones and deadlines.
3. **Agent: Execution Agent (General Purpose)**
- **Task:** Execute assigned tasks according to the project plan.
- **Sub-tasks:**
- Receive task assignments from the Planning Agent.
- Perform the assigned task.
- Report completion status and any encountered issues to the Planning Agent.
4. **Agent: Monitoring Agent**
- **Task:** Oversee the progress of all agents and ensure adherence to the project plan.
- **Sub-tasks:**
- Track the status of each task.
- Identify any deviations from the plan or potential bottlenecks.
- Report any critical issues or risks to the Planning Agent.
- Provide feedback on agent performance.
5. **Agent: Communication Agent**
- **Task:** Facilitate seamless communication between all agents.
- **Sub-tasks:**
- Relay messages and updates between agents.
- Ensure clarity and conciseness in all communications.
- Manage the flow of information according to defined protocols.
6. **Agent: Reporting Agent**
- **Task:** Compile and present project status reports.
- **Sub-tasks:**
- Gather progress updates from the Monitoring Agent and Planning Agent.
- Generate regular project status reports, highlighting achievements, challenges, and next steps.
- Disseminate reports to relevant stakeholders (if applicable).
**Execution Flow:**
1. **Research Agent** performs its research tasks.
2. **Planning Agent** receives the research output and develops the project plan.
3. **Planning Agent** assigns tasks to **Execution Agent(s)**, **Monitoring Agent**, **Communication Agent**, and **Reporting Agent**.
4. **Execution Agent(s)** begin executing their assigned tasks, reporting back to the **Planning Agent**.
5. **Monitoring Agent** continuously tracks progress and reports to the **Planning Agent**.
6. **Communication Agent** facilitates all inter-agent communication.
7. **Reporting Agent** compiles and disseminates reports based on information from the **Planning Agent** and **Monitoring Agent**.
8. **Planning Agent** oversees the entire process, making adjustments as needed and ensuring all tasks are completed successfully.
Description
When running an AutoAgents hierarchical workflow in praisonaiagents, the process fails with a hard error if the OpenAI API key is not set, even when OpenAI is not being used as the LLM. The manager task attempts to create an OpenAI client and raises an error about missing credentials, which interrupts the workflow and prevents completion.
Issue #860 is not fixed
Environment
Full Code
Steps to Reproduce
Expected Behavior
The workflow should not require or attempt to use an OpenAI API key when OpenAI is not the selected LLM.
The manager task and the entire workflow should execute and complete successfully without any dependency on OpenAI credentials, unless explicitly configured to use OpenAI.
Actual Behavior
The process fails with the following error:
"The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable"
The manager task cannot proceed due to this error, and the workflow is halted.
The error occurs even though the LLM specified is not OpenAI (e.g., Gemini).
Additional Context
Logs below
After this the execution halts