fix: tools for agent-prompt via ws
This commit is contained in:
1 parent
f217e7db3e
commit
3d8f77d154
2 files changed
+42
-5
No files matched your search
@@ -186,6 +186,38 @@ class AgentMixin:
|
||||
# inference.Message objects. get_agent_control is awaited lazily on first
|
||||
# iteration, keeping the control object alive for the generator's
|
||||
# lifetime.
|
||||
|
||||
def normalize_tool(t):
|
||||
# this function makes a lot of sense in ToolSpec itself...
|
||||
from tool import ToolSpec, ToolParameter
|
||||
if isinstance(t, dict):
|
||||
params = []
|
||||
|
||||
d = t.get('parameters', {})
|
||||
required = d.get('required', [])
|
||||
props = d.get('properties', {})
|
||||
|
||||
for key, p in props.items():
|
||||
params.append(ToolParameter(
|
||||
name=key,
|
||||
type=p.get('type'),
|
||||
description=p.get('description'),
|
||||
required=key in required,
|
||||
))
|
||||
return ToolSpec(
|
||||
name=t['name'],
|
||||
description=t['description'],
|
||||
parameters=params,
|
||||
)
|
||||
else:
|
||||
return t
|
||||
|
||||
if 'tools' in options:
|
||||
options = {**options}
|
||||
options['tools'] = [
|
||||
normalize_tool(t) for t in options['tools']
|
||||
]
|
||||
|
||||
control = await self.get_agent_control(agent_id)
|
||||
async for msg in control.prompt(instruction, input, **options):
|
||||
yield msg
|
||||
|
||||
Reference in new issue
Block a user