MCPcopy Create free account
hub / github.com/MiniMax-AI/Mini-Agent / test_wrapper_tool_calling

Function test_wrapper_tool_calling

tests/test_llm.py:128–197  ·  view source on GitHub ↗

Test LLM wrapper with tool calling.

()

Source from the content-addressed store, hash-verified

126
127@pytest.mark.asyncio
128async def test_wrapper_tool_calling():
129 """Test LLM wrapper with tool calling."""
130 print("\n=== Testing LLM Wrapper Tool Calling ===")
131
132 # Load config
133 config_path = Path("mini_agent/config/config.yaml")
134 with open(config_path, encoding="utf-8") as f:
135 config = yaml.safe_load(f)
136
137 # Create client with Anthropic provider
138 client = LLMClient(
139 api_key=config["api_key"],
140 provider=LLMProvider.ANTHROPIC,
141 model=config.get("model"),
142 )
143
144 # Messages requesting tool use
145 messages = [
146 Message(
147 role="system", content="You are a helpful assistant with access to tools."
148 ),
149 Message(role="user", content="Calculate 123 + 456 using the calculator tool."),
150 ]
151
152 # Define a simple calculator tool using dict format
153 tools = [
154 {
155 "name": "calculator",
156 "description": "Perform arithmetic operations",
157 "input_schema": {
158 "type": "object",
159 "properties": {
160 "operation": {
161 "type": "string",
162 "enum": ["add", "subtract", "multiply", "divide"],
163 "description": "The operation to perform",
164 },
165 "a": {
166 "type": "number",
167 "description": "First number",
168 },
169 "b": {
170 "type": "number",
171 "description": "Second number",
172 },
173 },
174 "required": ["operation", "a", "b"],
175 },
176 }
177 ]
178
179 try:
180 response = await client.generate(messages=messages, tools=tools)
181
182 print(f"Response: {response.content}")
183 print(f"Tool calls: {response.tool_calls}")
184 print(f"Finish reason: {response.finish_reason}")
185

Callers 1

mainFunction · 0.85

Calls 4

generateMethod · 0.95
LLMClientClass · 0.90
MessageClass · 0.90
getMethod · 0.80

Tested by

no test coverage detected