wip: add tools to agent control and improve tool class

This commit is contained in:
Shivering Ocelot committed 2026-06-08 05:18:38 -05:00
1 parent 6134c026a6
commit 9585008433
7 files changed
+144 -13

No files matched your search

+20 -2
View File
@@ -21,7 +21,7 @@ class Agent:
# - identifier (for kind in creation)
# - schema: list[AgentField{name, type: str}] (for configuration)
def __init__(self, app, data):
def __init__(self, app, data, resources=[]):
self.app = app
# These variables are set by '_set_basic_info'
@@ -31,6 +31,18 @@ class Agent:
# Auto populated based on the schema fields
agent_class = type(self)
self.config = {field.name: data.get(field.name, field.default) for field in getattr(agent_class, 'schema_fields', [])}
self.resources = resources
self.tools = []
for resource in self.resources:
if resource.kind != 'tool': continue
if resource.value.get('type') == 'native' and 'name' in resource.value:
tool_cls = next((t for t in self.app.tool_classes if t.tool_name() == resource.value['name']), None)
if tool_cls:
tool = tool_cls()
spec = tool.get_spec().clone()
spec.name = resource.key
self.tools.append(spec)
def _set_basic_info(self, id, name, user_id):
self.id = id
@@ -110,7 +122,7 @@ class Agent:
# Returns all resource values matching the kind and key
def get_resources(self, kind, key):
self.app
pass # TODO lol
class DebugAgent(Agent):
@@ -226,6 +238,12 @@ class AgentRun:
self.emit_event('reasoning', self.reasoning)
if chunk:
self.reasoning.feed(chunk)
def add_tools(self, tools):
if "tools" in self.input:
self.input["tools"] += tools
else:
self.input["tools"] = tools
def add_tool_call(self, tool_name, arguments):
self.emit_event("tool_call", {"name": tool_name, "arguments": arguments})