|
@@ -39,6 +39,26 @@ class ToolCallingChatClient:
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+class NoToolCallChatClient:
|
|
|
|
|
+ def __init__(self) -> None:
|
|
|
|
|
+ self.calls: list[dict] = []
|
|
|
|
|
+
|
|
|
|
|
+ async def stream_chat(
|
|
|
|
|
+ self,
|
|
|
|
|
+ messages: list[ChatMessage],
|
|
|
|
|
+ tools: list[dict],
|
|
|
|
|
+ params: AgentParams,
|
|
|
|
|
+ ) -> AsyncIterator[StreamItem]:
|
|
|
|
|
+ self.calls.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "messages": list(messages),
|
|
|
|
|
+ "tools": list(tools),
|
|
|
|
|
+ "params": params,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ yield StreamItem.message_delta("I should have called the tool.")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
async def test_event_agent_resolves_tool_arguments_with_llm_tool_call():
|
|
async def test_event_agent_resolves_tool_arguments_with_llm_tool_call():
|
|
|
chat_client = ToolCallingChatClient({"message": "LLM generated handoff"})
|
|
chat_client = ToolCallingChatClient({"message": "LLM generated handoff"})
|
|
@@ -86,6 +106,34 @@ async def test_event_agent_resolves_tool_arguments_with_llm_tool_call():
|
|
|
assert chat_client.calls[0]["params"].model == "event-model"
|
|
assert chat_client.calls[0]["params"].model == "event-model"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+@pytest.mark.asyncio
|
|
|
|
|
+async def test_event_agent_falls_back_to_context_arguments_when_llm_returns_no_tool_call():
|
|
|
|
|
+ chat_client = NoToolCallChatClient()
|
|
|
|
|
+ agent = EventAgent(
|
|
|
|
|
+ enabled_tools=["mock_search"],
|
|
|
|
|
+ chat_client=chat_client,
|
|
|
|
|
+ params=AgentParams(model="event-model", temperature=0, max_tokens=80),
|
|
|
|
|
+ )
|
|
|
|
|
+ event = ToolCallEvent(
|
|
|
|
|
+ id="call_1",
|
|
|
|
|
+ name="mock_search",
|
|
|
|
|
+ arguments={},
|
|
|
|
|
+ raw_arguments="{}",
|
|
|
|
|
+ )
|
|
|
|
|
+ history = [
|
|
|
|
|
+ ChatMessage(role="user", content="Find latency docs"),
|
|
|
|
|
+ ChatMessage(role="assistant", content="Need a search for latency docs"),
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ reply = await agent.handle(event, history=history)
|
|
|
|
|
+
|
|
|
|
|
+ payload = json.loads(reply.content)
|
|
|
|
|
+ assert payload["tool"] == "mock_search"
|
|
|
|
|
+ assert payload["query"] == "Need a search for latency docs"
|
|
|
|
|
+ assert "event agent did not return arguments" not in reply.content
|
|
|
|
|
+ assert chat_client.calls[0]["tools"][0]["function"]["name"] == "mock_search"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
async def test_event_agent_returns_registry_errors_for_disabled_and_unknown_tools():
|
|
async def test_event_agent_returns_registry_errors_for_disabled_and_unknown_tools():
|
|
|
registry = ToolRegistry(
|
|
registry = ToolRegistry(
|