feat: respect tool policy, oai execute deferred tools
This commit is contained in:
1 parent
1bd1880d9b
commit
c9a76e7fb3
2 files changed
+8
-8
No files matched your search
@@ -40,13 +40,15 @@ async def chat_completion_loop(app, run, messages, model_id=None, tools=None):
|
|||||||
|
|
||||||
run.emit_event('inference', msg)
|
run.emit_event('inference', msg)
|
||||||
|
|
||||||
if execute_tools and tool_calls:
|
|
||||||
for tc in tool_calls:
|
for tc in tool_calls:
|
||||||
tool = next((t for t in tools if t.name == tc.tool_name), None)
|
tool = next((t for t in tools if t.name == tc.tool_name), None)
|
||||||
if tool is None:
|
if tool is None:
|
||||||
print(f"[agent] unknown tool name: {tc.tool_name}")
|
print(f"[agent] unknown tool name: {tc.tool_name}")
|
||||||
continue
|
continue
|
||||||
|
if execute_tools:
|
||||||
tc.result = await tool.execute_async(**tc.arguments)
|
tc.result = await tool.execute_async(**tc.arguments)
|
||||||
|
else:
|
||||||
|
tc.tool = tool
|
||||||
|
|
||||||
# By default, end if there's no calls
|
# By default, end if there's no calls
|
||||||
else: break
|
else: break
|
||||||
@@ -79,9 +81,7 @@ class ExpertAgent(Agent):
|
|||||||
# Provide the agent's default tools unless the run supplies its own.
|
# Provide the agent's default tools unless the run supplies its own.
|
||||||
# Only agent-provided tools are executable within the loop.
|
# Only agent-provided tools are executable within the loop.
|
||||||
tools = run.input.get("tools", [])
|
tools = run.input.get("tools", [])
|
||||||
if tools:
|
if run.input.get('tool_policy') != 'caller':
|
||||||
run.input['tool_policy'] = 'ignore'
|
|
||||||
else:
|
|
||||||
tools += self.get_tools(run)
|
tools += self.get_tools(run)
|
||||||
|
|
||||||
print("Final tool object: " + repr(run.input.get('tools', [])))
|
print("Final tool object: " + repr(run.input.get('tools', [])))
|
||||||
|
|||||||
@@ -49,17 +49,17 @@ def route_tool_call(call, tool_names):
|
|||||||
return deferred
|
return deferred
|
||||||
|
|
||||||
|
|
||||||
async def execute_deferred(function_call):
|
async def execute_deferred(tc):
|
||||||
"""Execute a deferred (native) tool call.
|
"""Execute a deferred (native) tool call.
|
||||||
|
|
||||||
The output must be stored on the call itself (``function_call.result``).
|
The output must be stored on the call itself (``tc.result``).
|
||||||
|
|
||||||
TODO: resolve the ToolSpec for ``function_call.tool_name`` from the
|
TODO: resolve the ToolSpec for ``tc.tool_name`` from the
|
||||||
agent's native tools and dispatch through the existing tool
|
agent's native tools and dispatch through the existing tool
|
||||||
infrastructure (ToolSpec.execute_async), recording the result or error on
|
infrastructure (ToolSpec.execute_async), recording the result or error on
|
||||||
the call. Deferred execution needs more design work; stubbed for now.
|
the call. Deferred execution needs more design work; stubbed for now.
|
||||||
"""
|
"""
|
||||||
pass
|
tc.result = await tc.tool.execute_async(**tc.arguments)
|
||||||
|
|
||||||
|
|
||||||
def attach_run_handlers(run, tool_names):
|
def attach_run_handlers(run, tool_names):
|
||||||
|
|||||||
Reference in new issue
Block a user