agentic-blocks 0.1.10__py3-none-any.whl → 0.1.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentic_blocks/utils/tools_utils.py +131 -1
- {agentic_blocks-0.1.10.dist-info → agentic_blocks-0.1.11.dist-info}/METADATA +1 -1
- {agentic_blocks-0.1.10.dist-info → agentic_blocks-0.1.11.dist-info}/RECORD +6 -6
- {agentic_blocks-0.1.10.dist-info → agentic_blocks-0.1.11.dist-info}/WHEEL +0 -0
- {agentic_blocks-0.1.10.dist-info → agentic_blocks-0.1.11.dist-info}/licenses/LICENSE +0 -0
- {agentic_blocks-0.1.10.dist-info → agentic_blocks-0.1.11.dist-info}/top_level.txt +0 -0
@@ -43,4 +43,134 @@ def langchain_tools_to_openai_format(tools: List) -> List[Dict[str, Any]]:
|
|
43
43
|
List of dictionaries in OpenAI function calling format, compatible with
|
44
44
|
MCPClient.list_tools() output and call_llm() tools parameter
|
45
45
|
"""
|
46
|
-
return [langchain_tool_to_openai_format(tool) for tool in tools]
|
46
|
+
return [langchain_tool_to_openai_format(tool) for tool in tools]
|
47
|
+
|
48
|
+
|
49
|
+
def create_tool_registry(tools: List) -> Dict[str, Any]:
|
50
|
+
"""
|
51
|
+
Create a registry mapping tool names to LangChain tool instances.
|
52
|
+
|
53
|
+
Args:
|
54
|
+
tools: List of langchain_core.tools.structured.StructuredTool instances
|
55
|
+
|
56
|
+
Returns:
|
57
|
+
Dictionary mapping tool names to tool instances
|
58
|
+
"""
|
59
|
+
return {tool.name: tool for tool in tools}
|
60
|
+
|
61
|
+
|
62
|
+
def execute_tool_call(tool_call: Dict[str, Any], tool_registry: Dict[str, Any]) -> Dict[str, Any]:
|
63
|
+
"""
|
64
|
+
Execute a single tool call using LangChain tool registry.
|
65
|
+
|
66
|
+
Args:
|
67
|
+
tool_call: Dictionary with 'tool_name', 'arguments', and 'tool_call_id' keys
|
68
|
+
tool_registry: Registry mapping tool names to tool instances
|
69
|
+
|
70
|
+
Returns:
|
71
|
+
Dictionary with 'tool_call_id', 'result', and 'is_error' keys
|
72
|
+
"""
|
73
|
+
tool_name = tool_call.get('tool_name')
|
74
|
+
arguments = tool_call.get('arguments', {})
|
75
|
+
tool_call_id = tool_call.get('tool_call_id')
|
76
|
+
|
77
|
+
try:
|
78
|
+
if tool_name not in tool_registry:
|
79
|
+
raise ValueError(f"Tool '{tool_name}' not found in registry")
|
80
|
+
|
81
|
+
tool = tool_registry[tool_name]
|
82
|
+
result = tool.invoke(arguments)
|
83
|
+
|
84
|
+
return {
|
85
|
+
'tool_call_id': tool_call_id,
|
86
|
+
'result': result,
|
87
|
+
'is_error': False
|
88
|
+
}
|
89
|
+
except Exception as e:
|
90
|
+
return {
|
91
|
+
'tool_call_id': tool_call_id,
|
92
|
+
'result': f"Error executing tool '{tool_name}': {str(e)}",
|
93
|
+
'is_error': True
|
94
|
+
}
|
95
|
+
|
96
|
+
|
97
|
+
def execute_pending_tool_calls(messages, tool_registry: Dict[str, Any]) -> List[Dict[str, Any]]:
|
98
|
+
"""
|
99
|
+
Execute all pending tool calls from a Messages instance and add responses back.
|
100
|
+
|
101
|
+
Args:
|
102
|
+
messages: Messages instance with pending tool calls
|
103
|
+
tool_registry: Registry mapping tool names to tool instances
|
104
|
+
|
105
|
+
Returns:
|
106
|
+
List of execution results compatible with Messages.add_tool_responses format
|
107
|
+
"""
|
108
|
+
pending_tool_calls = messages.get_pending_tool_calls()
|
109
|
+
results = []
|
110
|
+
|
111
|
+
for tool_call in pending_tool_calls:
|
112
|
+
result = execute_tool_call(tool_call, tool_registry)
|
113
|
+
|
114
|
+
# Convert to format expected by Messages.add_tool_responses
|
115
|
+
if result['is_error']:
|
116
|
+
tool_response = {
|
117
|
+
'tool_call_id': result['tool_call_id'],
|
118
|
+
'is_error': True,
|
119
|
+
'error': result['result']
|
120
|
+
}
|
121
|
+
else:
|
122
|
+
tool_response = {
|
123
|
+
'tool_call_id': result['tool_call_id'],
|
124
|
+
'is_error': False,
|
125
|
+
'tool_response': result['result']
|
126
|
+
}
|
127
|
+
|
128
|
+
results.append(tool_response)
|
129
|
+
|
130
|
+
# Add tool response back to messages using individual method
|
131
|
+
if result['is_error']:
|
132
|
+
messages.add_tool_response(result['tool_call_id'], result['result'])
|
133
|
+
else:
|
134
|
+
messages.add_tool_response(result['tool_call_id'], str(result['result']))
|
135
|
+
|
136
|
+
return results
|
137
|
+
|
138
|
+
|
139
|
+
def execute_and_add_tool_responses(messages, tool_registry: Dict[str, Any]) -> List[Dict[str, Any]]:
|
140
|
+
"""
|
141
|
+
Execute all pending tool calls and add them using Messages.add_tool_responses batch method.
|
142
|
+
|
143
|
+
Args:
|
144
|
+
messages: Messages instance with pending tool calls
|
145
|
+
tool_registry: Registry mapping tool names to tool instances
|
146
|
+
|
147
|
+
Returns:
|
148
|
+
List of execution results compatible with Messages.add_tool_responses format
|
149
|
+
"""
|
150
|
+
pending_tool_calls = messages.get_pending_tool_calls()
|
151
|
+
results = []
|
152
|
+
|
153
|
+
for tool_call in pending_tool_calls:
|
154
|
+
result = execute_tool_call(tool_call, tool_registry)
|
155
|
+
|
156
|
+
# Convert to format expected by Messages.add_tool_responses
|
157
|
+
if result['is_error']:
|
158
|
+
tool_response = {
|
159
|
+
'tool_call_id': result['tool_call_id'],
|
160
|
+
'is_error': True,
|
161
|
+
'error': result['result']
|
162
|
+
}
|
163
|
+
else:
|
164
|
+
tool_response = {
|
165
|
+
'tool_call_id': result['tool_call_id'],
|
166
|
+
'is_error': False,
|
167
|
+
'tool_response': result['result']
|
168
|
+
}
|
169
|
+
|
170
|
+
results.append(tool_response)
|
171
|
+
|
172
|
+
# Add all responses at once using the batch method
|
173
|
+
if results:
|
174
|
+
messages.add_tool_responses(results)
|
175
|
+
|
176
|
+
return results
|
@@ -2,9 +2,9 @@ agentic_blocks/__init__.py,sha256=LJy2tzTwX9ZjPw8dqkXOWiude7ZDDIaBIvaLC8U4d_Y,43
|
|
2
2
|
agentic_blocks/llm.py,sha256=q2Utx2NiffLrp7VHmQIRZtBtrnQSMFtqCeYs9ynj0Ww,5335
|
3
3
|
agentic_blocks/mcp_client.py,sha256=15mIN_Qw0OVNJAvfgO3jVZS4-AU4TtvEQSFDlL9ruqA,9773
|
4
4
|
agentic_blocks/messages.py,sha256=dxaR_-IiH8n7pZygFDiUt8n7mMOm--FRuN-xCQEuewo,11758
|
5
|
-
agentic_blocks/utils/tools_utils.py,sha256=
|
6
|
-
agentic_blocks-0.1.
|
7
|
-
agentic_blocks-0.1.
|
8
|
-
agentic_blocks-0.1.
|
9
|
-
agentic_blocks-0.1.
|
10
|
-
agentic_blocks-0.1.
|
5
|
+
agentic_blocks/utils/tools_utils.py,sha256=SUK8tsogadc2sNeoF12RgQ5dtU1EpKfEKWphck1zQ3Q,5750
|
6
|
+
agentic_blocks-0.1.11.dist-info/licenses/LICENSE,sha256=r4IcBaAjTv3-yfjXgDPuRD953Qci0Y0nQn5JfHwLyBY,1073
|
7
|
+
agentic_blocks-0.1.11.dist-info/METADATA,sha256=fnSsadfcPoHLPRsCJxbuhZ2EQlQpKmZLap6D2G4Nbjw,11944
|
8
|
+
agentic_blocks-0.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
9
|
+
agentic_blocks-0.1.11.dist-info/top_level.txt,sha256=-1a4RAemqicXLU1rRzw4QHV3KlNeQDNxVs3m2gAT238,15
|
10
|
+
agentic_blocks-0.1.11.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|