Example 1: Task completes after any tool is generated and handled by agent
()
| 95 | |
| 96 | |
| 97 | def example1_tool_then_agent(): |
| 98 | """Example 1: Task completes after any tool is generated and handled by agent""" |
| 99 | print("\n=== Example 1: Tool -> Agent Response ===") |
| 100 | |
| 101 | agent = ChatAgent( |
| 102 | ChatAgentConfig( |
| 103 | name="Assistant", |
| 104 | system_message=""" |
| 105 | You are a helpful assistant with access to calculator and search tools. |
| 106 | Use the appropriate tool when asked to calculate or search for something. |
| 107 | """, |
| 108 | ) |
| 109 | ) |
| 110 | agent.enable_message(CalculatorTool, use=True, handle=True) |
| 111 | agent.enable_message(SearchTool, use=True, handle=True) |
| 112 | |
| 113 | # Task completes after: Tool -> Agent Response |
| 114 | # Using DSL (recommended for simple patterns): |
| 115 | # config = TaskConfig(done_sequences=["T, A"]) |
| 116 | |
| 117 | # Using full syntax (for more control): |
| 118 | config = TaskConfig( |
| 119 | done_sequences=[ |
| 120 | DoneSequence( |
| 121 | name="tool_handled", |
| 122 | events=[ |
| 123 | AgentEvent(event_type=EventType.TOOL), |
| 124 | AgentEvent(event_type=EventType.AGENT_RESPONSE), |
| 125 | ], |
| 126 | ) |
| 127 | ] |
| 128 | ) |
| 129 | |
| 130 | task = Task(agent, config=config) |
| 131 | print("Task will complete after any tool is used and handled.") |
| 132 | _ = task.run("What is 25 * 4?") |
| 133 | # print(f"Final result: {_.content}") |
| 134 | |
| 135 | |
| 136 | def example2_specific_tool_sequence(): |
no test coverage detected
searching dependent graphs…