MCPcopy
hub / github.com/langroid/langroid / test_done_sequence_specific_tool

Function test_done_sequence_specific_tool

tests/main/test_done_sequences.py:77–130  ·  view source on GitHub ↗

Test that task terminates only after specific tool

(test_settings: Settings)

Source from the content-addressed store, hash-verified

75
76
77def test_done_sequence_specific_tool(test_settings: Settings):
78 """Test that task terminates only after specific tool"""
79 set_global(test_settings)
80
81 class AnotherTool(ToolMessage):
82 request: str = "another_tool"
83 purpose: str = "Another tool"
84 data: str
85
86 def handle(self) -> str:
87 return f"Processed data: {self.data}"
88
89 # Mock LLM that alternates between tools
90 call_count = 0
91
92 def mock_response(x):
93 nonlocal call_count
94 call_count += 1
95 if call_count == 1:
96 return '{"request": "another_tool", "data": "test"}'
97 else:
98 return '{"request": "simple_tool", "value": "test"}'
99
100 agent = ChatAgent(
101 ChatAgentConfig(
102 name="TestAgent",
103 llm=MockLMConfig(response_fn=mock_response),
104 )
105 )
106 agent.enable_message(SimpleTool)
107 agent.enable_message(AnotherTool)
108
109 # Configure to be done only after simple_tool
110 config = TaskConfig(
111 done_sequences=[
112 DoneSequence(
113 name="specific_tool",
114 events=[
115 AgentEvent(
116 event_type=EventType.SPECIFIC_TOOL, tool_name="simple_tool"
117 ),
118 AgentEvent(event_type=EventType.AGENT_RESPONSE),
119 ],
120 )
121 ]
122 )
123
124 task = Task(agent, config=config, interactive=False)
125 result = task.run("Generate tools", turns=10)
126
127 assert result is not None
128 # Verify simple_tool was generated (it's in the last assistant message)
129 last_assistant_msg = agent.message_history[-1]
130 assert "simple_tool" in last_assistant_msg.content
131
132
133def test_done_sequence_llm_agent_llm(test_settings: Settings):

Callers

nothing calls this directly

Calls 10

enable_messageMethod · 0.95
runMethod · 0.95
set_globalFunction · 0.90
ChatAgentClass · 0.90
ChatAgentConfigClass · 0.90
MockLMConfigClass · 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…