----------------------
I understand you're having trouble accessing the internal state of the StructuredPlannerAgent. Let me help you with that.
The StructuredPlannerAgent maintains an internal state that includes information about plans, tasks, and their execution status. You can access this state directly through the agent's
state
attribute.
Here's how you can access and inspect the state:
# Assuming you've already created your agent
agent = StructuredPlannerAgent(worker, tools=[lyft_tool, uber_tool], verbose=True)
# Create a plan
plan_id = agent.create_plan("Your task description here")
# Access the plan from the state
plan = agent.state.plan_dict[plan_id]
# Inspect the plan's sub-tasks
for sub_task in plan.sub_tasks:
print(f"===== Sub Task {sub_task.name} =====")
print("Expected output: ", sub_task.expected_output)
print("Dependencies: ", sub_task.dependencies)
You can also check which tasks are ready to be executed next:
next_tasks = agent.state.get_next_sub_tasks(plan_id)
And after executing tasks, you can mark them as complete:
agent.mark_task_complete(plan_id, sub_task.name)
If you want to see if there are any remaining tasks:
next_tasks = agent.get_next_tasks(plan_id)
if len(next_tasks) == 0:
print("All tasks completed!")
These examples are based on the low-level API usage shown in the
StructuredPlannerAgent documentation.
If you're looking for more detailed information about a specific aspect of the agent's state, please let me know!
kapa.ai
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------