MCPcopy
hub / github.com/langroid/langroid / example1_tool_then_agent

Function example1_tool_then_agent

examples/basic/done_sequences_example.py:97–133  ·  view source on GitHub ↗

Example 1: Task completes after any tool is generated and handled by agent

()

Source from the content-addressed store, hash-verified

95
96
97def 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
136def example2_specific_tool_sequence():

Callers 1

Calls 8

enable_messageMethod · 0.95
runMethod · 0.95
ChatAgentClass · 0.90
ChatAgentConfigClass · 0.90
TaskConfigClass · 0.90
DoneSequenceClass · 0.90
AgentEventClass · 0.90
TaskClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…