agentic-blocks 0.1.13__tar.gz → 0.1.15__tar.gz
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-0.1.13/src/agentic_blocks.egg-info → agentic_blocks-0.1.15}/PKG-INFO +1 -1
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/pyproject.toml +1 -1
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks/utils/tools_utils.py +70 -68
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15/src/agentic_blocks.egg-info}/PKG-INFO +1 -1
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/LICENSE +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/README.md +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/setup.cfg +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks/__init__.py +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks/llm.py +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks/mcp_client.py +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks/messages.py +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks.egg-info/SOURCES.txt +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks.egg-info/dependency_links.txt +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks.egg-info/requires.txt +0 -0
- {agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks.egg-info/top_level.txt +0 -0
@@ -14,7 +14,7 @@ agentic_blocks = []
|
|
14
14
|
|
15
15
|
[project]
|
16
16
|
name = "agentic-blocks"
|
17
|
-
version = "0.1.
|
17
|
+
version = "0.1.15"
|
18
18
|
description = "Simple building blocks for agentic AI systems with MCP client and conversation management"
|
19
19
|
readme = "README.md"
|
20
20
|
requires-python = ">=3.11"
|
@@ -8,16 +8,16 @@ from typing import Dict, Any, List
|
|
8
8
|
def langchain_tool_to_openai_format(tool) -> Dict[str, Any]:
|
9
9
|
"""
|
10
10
|
Convert a LangChain StructuredTool to OpenAI function calling format.
|
11
|
-
|
11
|
+
|
12
12
|
Args:
|
13
13
|
tool: A langchain_core.tools.structured.StructuredTool instance
|
14
|
-
|
14
|
+
|
15
15
|
Returns:
|
16
|
-
Dictionary in OpenAI function calling format, compatible with
|
16
|
+
Dictionary in OpenAI function calling format, compatible with
|
17
17
|
MCPClient.list_tools() output and call_llm() tools parameter
|
18
18
|
"""
|
19
19
|
schema = tool.args_schema.model_json_schema()
|
20
|
-
|
20
|
+
|
21
21
|
# Resolve $ref references by flattening $defs into the schema
|
22
22
|
# OpenAI doesn't support $ref/$defs, so we need to inline all definitions
|
23
23
|
def resolve_refs(obj, defs):
|
@@ -38,39 +38,39 @@ def langchain_tool_to_openai_format(tool) -> Dict[str, Any]:
|
|
38
38
|
return [resolve_refs(item, defs) for item in obj]
|
39
39
|
else:
|
40
40
|
return obj
|
41
|
-
|
41
|
+
|
42
42
|
# Get definitions for reference resolution
|
43
43
|
defs = schema.get("$defs", {})
|
44
|
-
|
44
|
+
|
45
45
|
# Resolve references in properties
|
46
46
|
resolved_properties = resolve_refs(schema.get("properties", {}), defs)
|
47
|
-
|
47
|
+
|
48
48
|
# Build parameters object without $defs
|
49
49
|
parameters = {
|
50
50
|
"type": "object",
|
51
51
|
"properties": resolved_properties,
|
52
|
-
"required": schema.get("required", [])
|
52
|
+
"required": schema.get("required", []),
|
53
53
|
}
|
54
|
-
|
54
|
+
|
55
55
|
return {
|
56
56
|
"type": "function",
|
57
57
|
"function": {
|
58
58
|
"name": schema.get("title", tool.name),
|
59
59
|
"description": tool.description or schema.get("description", ""),
|
60
|
-
"parameters": parameters
|
61
|
-
}
|
60
|
+
"parameters": parameters,
|
61
|
+
},
|
62
62
|
}
|
63
63
|
|
64
64
|
|
65
65
|
def langchain_tools_to_openai_format(tools: List) -> List[Dict[str, Any]]:
|
66
66
|
"""
|
67
67
|
Convert a list of LangChain StructuredTools to OpenAI function calling format.
|
68
|
-
|
68
|
+
|
69
69
|
Args:
|
70
70
|
tools: List of langchain_core.tools.structured.StructuredTool instances
|
71
|
-
|
71
|
+
|
72
72
|
Returns:
|
73
|
-
List of dictionaries in OpenAI function calling format, compatible with
|
73
|
+
List of dictionaries in OpenAI function calling format, compatible with
|
74
74
|
MCPClient.list_tools() output and call_llm() tools parameter
|
75
75
|
"""
|
76
76
|
return [langchain_tool_to_openai_format(tool) for tool in tools]
|
@@ -79,128 +79,130 @@ def langchain_tools_to_openai_format(tools: List) -> List[Dict[str, Any]]:
|
|
79
79
|
def create_tool_registry(tools: List) -> Dict[str, Any]:
|
80
80
|
"""
|
81
81
|
Create a registry mapping tool names to LangChain tool instances.
|
82
|
-
|
82
|
+
|
83
83
|
Args:
|
84
84
|
tools: List of langchain_core.tools.structured.StructuredTool instances
|
85
|
-
|
85
|
+
|
86
86
|
Returns:
|
87
87
|
Dictionary mapping tool names to tool instances
|
88
88
|
"""
|
89
89
|
return {tool.name: tool for tool in tools}
|
90
90
|
|
91
91
|
|
92
|
-
def execute_tool_call(
|
92
|
+
def execute_tool_call(
|
93
|
+
tool_call: Dict[str, Any], tool_registry: Dict[str, Any]
|
94
|
+
) -> Dict[str, Any]:
|
93
95
|
"""
|
94
96
|
Execute a single tool call using LangChain tool registry.
|
95
|
-
|
97
|
+
|
96
98
|
Args:
|
97
99
|
tool_call: Dictionary with 'tool_name', 'arguments', and 'tool_call_id' keys
|
98
100
|
tool_registry: Registry mapping tool names to tool instances
|
99
|
-
|
101
|
+
|
100
102
|
Returns:
|
101
103
|
Dictionary with 'tool_call_id', 'result', and 'is_error' keys
|
102
104
|
"""
|
103
|
-
tool_name = tool_call.get(
|
104
|
-
arguments = tool_call.get(
|
105
|
-
tool_call_id = tool_call.get(
|
106
|
-
|
105
|
+
tool_name = tool_call.get("tool_name")
|
106
|
+
arguments = tool_call.get("arguments", {})
|
107
|
+
tool_call_id = tool_call.get("tool_call_id")
|
108
|
+
|
107
109
|
try:
|
108
110
|
if tool_name not in tool_registry:
|
109
111
|
raise ValueError(f"Tool '{tool_name}' not found in registry")
|
110
|
-
|
112
|
+
|
111
113
|
tool = tool_registry[tool_name]
|
112
114
|
result = tool.invoke(arguments)
|
113
|
-
|
114
|
-
return {
|
115
|
-
'tool_call_id': tool_call_id,
|
116
|
-
'result': result,
|
117
|
-
'is_error': False
|
118
|
-
}
|
115
|
+
|
116
|
+
return {"tool_call_id": tool_call_id, "result": result, "is_error": False}
|
119
117
|
except Exception as e:
|
120
118
|
return {
|
121
|
-
|
122
|
-
|
123
|
-
|
119
|
+
"tool_call_id": tool_call_id,
|
120
|
+
"result": f"Error executing tool '{tool_name}': {str(e)}",
|
121
|
+
"is_error": True,
|
124
122
|
}
|
125
123
|
|
126
124
|
|
127
|
-
def execute_pending_tool_calls(
|
125
|
+
def execute_pending_tool_calls(
|
126
|
+
messages, tool_registry: Dict[str, Any]
|
127
|
+
) -> List[Dict[str, Any]]:
|
128
128
|
"""
|
129
129
|
Execute all pending tool calls from a Messages instance and add responses back.
|
130
|
-
|
130
|
+
|
131
131
|
Args:
|
132
132
|
messages: Messages instance with pending tool calls
|
133
133
|
tool_registry: Registry mapping tool names to tool instances
|
134
|
-
|
134
|
+
|
135
135
|
Returns:
|
136
136
|
List of execution results compatible with Messages.add_tool_responses format
|
137
137
|
"""
|
138
138
|
pending_tool_calls = messages.get_pending_tool_calls()
|
139
139
|
results = []
|
140
|
-
|
140
|
+
|
141
141
|
for tool_call in pending_tool_calls:
|
142
142
|
result = execute_tool_call(tool_call, tool_registry)
|
143
|
-
|
143
|
+
|
144
144
|
# Convert to format expected by Messages.add_tool_responses
|
145
|
-
if result[
|
145
|
+
if result["is_error"]:
|
146
146
|
tool_response = {
|
147
|
-
|
148
|
-
|
149
|
-
|
147
|
+
"tool_call_id": result["tool_call_id"],
|
148
|
+
"is_error": True,
|
149
|
+
"error": result["result"],
|
150
150
|
}
|
151
151
|
else:
|
152
152
|
tool_response = {
|
153
|
-
|
154
|
-
|
155
|
-
|
153
|
+
"tool_call_id": result["tool_call_id"],
|
154
|
+
"is_error": False,
|
155
|
+
"tool_response": result["result"],
|
156
156
|
}
|
157
|
-
|
157
|
+
|
158
158
|
results.append(tool_response)
|
159
|
-
|
159
|
+
|
160
160
|
# Add tool response back to messages using individual method
|
161
|
-
if result['is_error']:
|
162
|
-
|
163
|
-
else:
|
164
|
-
|
165
|
-
|
161
|
+
# if result['is_error']:
|
162
|
+
# messages.add_tool_response(result['tool_call_id'], result['result'])
|
163
|
+
# else:
|
164
|
+
# messages.add_tool_response(result['tool_call_id'], str(result['result']))
|
165
|
+
|
166
166
|
return results
|
167
167
|
|
168
168
|
|
169
|
-
def execute_and_add_tool_responses(
|
169
|
+
def execute_and_add_tool_responses(
|
170
|
+
messages, tool_registry: Dict[str, Any]
|
171
|
+
) -> List[Dict[str, Any]]:
|
170
172
|
"""
|
171
173
|
Execute all pending tool calls and add them using Messages.add_tool_responses batch method.
|
172
|
-
|
174
|
+
|
173
175
|
Args:
|
174
176
|
messages: Messages instance with pending tool calls
|
175
177
|
tool_registry: Registry mapping tool names to tool instances
|
176
|
-
|
178
|
+
|
177
179
|
Returns:
|
178
180
|
List of execution results compatible with Messages.add_tool_responses format
|
179
181
|
"""
|
180
182
|
pending_tool_calls = messages.get_pending_tool_calls()
|
181
183
|
results = []
|
182
|
-
|
184
|
+
|
183
185
|
for tool_call in pending_tool_calls:
|
184
186
|
result = execute_tool_call(tool_call, tool_registry)
|
185
|
-
|
187
|
+
|
186
188
|
# Convert to format expected by Messages.add_tool_responses
|
187
|
-
if result[
|
189
|
+
if result["is_error"]:
|
188
190
|
tool_response = {
|
189
|
-
|
190
|
-
|
191
|
-
|
191
|
+
"tool_call_id": result["tool_call_id"],
|
192
|
+
"is_error": True,
|
193
|
+
"error": result["result"],
|
192
194
|
}
|
193
195
|
else:
|
194
196
|
tool_response = {
|
195
|
-
|
196
|
-
|
197
|
-
|
197
|
+
"tool_call_id": result["tool_call_id"],
|
198
|
+
"is_error": False,
|
199
|
+
"tool_response": result["result"],
|
198
200
|
}
|
199
|
-
|
201
|
+
|
200
202
|
results.append(tool_response)
|
201
|
-
|
203
|
+
|
202
204
|
# Add all responses at once using the batch method
|
203
205
|
if results:
|
204
206
|
messages.add_tool_responses(results)
|
205
|
-
|
206
|
-
return results
|
207
|
+
|
208
|
+
return results
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{agentic_blocks-0.1.13 → agentic_blocks-0.1.15}/src/agentic_blocks.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|