-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_simulator.py
More file actions
54 lines (40 loc) · 1.35 KB
/
tool_simulator.py
File metadata and controls
54 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from __future__ import annotations
from typing import Any, Dict, List
class ToolSimulator:
def __init__(self, tool_scenarios: Dict[str, Any] | None = None):
self.tool_scenarios = tool_scenarios or {}
def run(self, tool_name: str, input_payload: Dict[str, Any]) -> Dict[str, Any]:
if tool_name not in self.tool_scenarios:
return {
"error": f"Unknown tool: {tool_name}",
"success": False,
}
tool_data = self.tool_scenarios[tool_name]
# Simple key-based lookup (order_id, etc.)
key = list(input_payload.values())[0] if input_payload else None
if key in tool_data:
return {
"success": True,
"data": tool_data[key],
}
return {
"success": False,
"error": f"No data found for input: {input_payload}",
}
def simulate_tool_sequence(
simulator: ToolSimulator,
steps: List[Dict[str, Any]],
) -> List[Dict[str, Any]]:
trace = []
for step in steps:
tool = step["tool"]
input_payload = step.get("input", {})
output = simulator.run(tool, input_payload)
trace.append(
{
"tool": tool,
"input": input_payload,
"output": output,
}
)
return trace