|
|
@@ -7,6 +7,7 @@ import pytest
|
|
|
|
|
|
from agent_lab.application.contracts import AgentParams, DebugRunRequest, EventAgentParams
|
|
|
from agent_lab.application.runtime import DebugRuntime
|
|
|
+from agent_lab.application.tools import ToolDefinition, ToolRegistry
|
|
|
from agent_lab.domain.events import ToolCallEvent
|
|
|
from agent_lab.domain.messages import ChatMessage, StreamItem
|
|
|
|
|
|
@@ -96,6 +97,20 @@ class StrictHistoryChatClient:
|
|
|
yield StreamItem.message_delta("final answer")
|
|
|
|
|
|
|
|
|
+class ToolCapturingChatClient:
|
|
|
+ def __init__(self) -> None:
|
|
|
+ self.tools: list[dict[str, Any]] = []
|
|
|
+
|
|
|
+ async def stream_chat(
|
|
|
+ self,
|
|
|
+ messages: list[ChatMessage],
|
|
|
+ tools: list[dict],
|
|
|
+ params: AgentParams,
|
|
|
+ ) -> AsyncIterator[StreamItem]:
|
|
|
+ self.tools = list(tools)
|
|
|
+ yield StreamItem.message_delta("final answer")
|
|
|
+
|
|
|
+
|
|
|
def test_runtime_queues_exposes_input_output_and_events_queues():
|
|
|
RuntimeQueues = _runtime_queues_class()
|
|
|
|
|
|
@@ -257,3 +272,54 @@ async def test_runtime_preserves_assistant_tool_calls_before_tool_reply():
|
|
|
]
|
|
|
assert tool_message.tool_call_id == "call_1"
|
|
|
assert outputs[-1] == {"type": "done"}
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.asyncio
|
|
|
+async def test_runtime_passes_selected_tool_schema_from_registry_to_chat_agent():
|
|
|
+ registry = ToolRegistry(
|
|
|
+ [
|
|
|
+ ToolDefinition(
|
|
|
+ name="handoff_note",
|
|
|
+ description="Registry-owned handoff tool.",
|
|
|
+ parameters={
|
|
|
+ "type": "object",
|
|
|
+ "properties": {
|
|
|
+ "message": {"type": "string"},
|
|
|
+ "priority": {"type": "number"},
|
|
|
+ },
|
|
|
+ "required": ["message"],
|
|
|
+ },
|
|
|
+ handler=lambda event: {"tool": event.name, "message": "handled"},
|
|
|
+ )
|
|
|
+ ]
|
|
|
+ )
|
|
|
+ request = DebugRunRequest(
|
|
|
+ user_message="debug this",
|
|
|
+ system_prompts=[],
|
|
|
+ pre_messages=[],
|
|
|
+ chat_agent=AgentParams(model="fake-model", temperature=0.1, max_tokens=200),
|
|
|
+ event_agent=EventAgentParams(enabled_tools=["handoff_note"], max_event_loops=2),
|
|
|
+ )
|
|
|
+ client = ToolCapturingChatClient()
|
|
|
+ runtime = DebugRuntime(client, registry=registry)
|
|
|
+
|
|
|
+ outputs = [message async for message in runtime.run(request)]
|
|
|
+
|
|
|
+ assert outputs[-1] == {"type": "done"}
|
|
|
+ assert client.tools == [
|
|
|
+ {
|
|
|
+ "type": "function",
|
|
|
+ "function": {
|
|
|
+ "name": "handoff_note",
|
|
|
+ "description": "Registry-owned handoff tool.",
|
|
|
+ "parameters": {
|
|
|
+ "type": "object",
|
|
|
+ "properties": {
|
|
|
+ "message": {"type": "string"},
|
|
|
+ "priority": {"type": "number"},
|
|
|
+ },
|
|
|
+ "required": ["message"],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ ]
|