|
| 1 | +"""Standard LangChain unit tests for tools.""" |
| 2 | + |
| 3 | +from typing import Type |
| 4 | +from unittest.mock import MagicMock |
| 5 | + |
| 6 | +from a2a.types import AgentCapabilities, AgentCard |
| 7 | +from langchain_ampersend.a2a.toolkit import ( |
| 8 | + A2AToolkit, |
| 9 | + GetAgentDetailsTool, |
| 10 | + SendMessageTool, |
| 11 | +) |
| 12 | +from langchain_tests.unit_tests import ToolsUnitTests |
| 13 | + |
| 14 | + |
| 15 | +def _make_mock_toolkit() -> A2AToolkit: |
| 16 | + """Create a mock toolkit with initialized card.""" |
| 17 | + mock_treasurer = MagicMock() |
| 18 | + toolkit = A2AToolkit( |
| 19 | + remote_agent_url="http://test-agent.com", |
| 20 | + treasurer=mock_treasurer, |
| 21 | + ) |
| 22 | + toolkit._card = AgentCard( |
| 23 | + name="test_agent", |
| 24 | + description="A test agent", |
| 25 | + url="http://test-agent.com", |
| 26 | + capabilities=AgentCapabilities(streaming=True), |
| 27 | + default_input_modes=[], |
| 28 | + default_output_modes=[], |
| 29 | + skills=[], |
| 30 | + version="1.0.0", |
| 31 | + ) |
| 32 | + return toolkit |
| 33 | + |
| 34 | + |
| 35 | +class TestGetAgentDetailsToolStandard(ToolsUnitTests): |
| 36 | + @property |
| 37 | + def tool_constructor(self) -> Type[GetAgentDetailsTool]: |
| 38 | + return GetAgentDetailsTool |
| 39 | + |
| 40 | + @property |
| 41 | + def tool_constructor_params(self) -> dict: |
| 42 | + return {"toolkit": _make_mock_toolkit()} |
| 43 | + |
| 44 | + @property |
| 45 | + def tool_invoke_params_example(self) -> dict: |
| 46 | + return {} # GetAgentDetailsTool takes no parameters |
| 47 | + |
| 48 | + |
| 49 | +class TestSendMessageToolStandard(ToolsUnitTests): |
| 50 | + @property |
| 51 | + def tool_constructor(self) -> Type[SendMessageTool]: |
| 52 | + return SendMessageTool |
| 53 | + |
| 54 | + @property |
| 55 | + def tool_constructor_params(self) -> dict: |
| 56 | + return {"toolkit": _make_mock_toolkit()} |
| 57 | + |
| 58 | + @property |
| 59 | + def tool_invoke_params_example(self) -> dict: |
| 60 | + return {"message": "Hello, agent!"} |
0 commit comments