Skip to content

Commit

Permalink
fix: tool params format issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hughlv committed Feb 10, 2025
1 parent e2d0419 commit 321aa1f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 70 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ Once services are running, access:
- API: http://localhost:5004 (OpenAPI docs: http://localhost:5004/docs)
- Frontend: http://localhost:2855

### Observability with AgentOps

We use [AgentOps](https://agentops.ai) to monitor the performance of the system. To enable it, you can set environment variable `AGENTOPS_API_KEY` in `api/.env`.

## 👨‍💻 Contributing

We welcome all contributions! This includes code, documentation, and other project aspects. Open a [GitHub Issue](https://github.com/hughlv/agentok/issues/new) or join our [Discord Server](https://discord.gg/xBQxwRSWfm).
Expand Down
42 changes: 14 additions & 28 deletions api/agentok_api/services/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,59 +305,45 @@ def build_tool_dict(self, project: Project):
return tool_dict

def generate_tool_assignments(self, edges, tool_dict, nodes):
# Prepare the tool assignments
tool_assignments = {}

# First, process the regular tool assignments from edges
# Process regular tool assignments from edges
for edge in edges:
if edge.get("data") is not None and edge["data"].get("tools") is not None:
# Iterate over edge.data.tools.llm and append node.id to the respective tool_id in llm
for tool_id in edge["data"]["tools"]:
if tool_id in tool_dict:
if tool_id not in tool_assignments:
tool_assignments[tool_id] = {"execution": [], "llm": []}
tool_assignments[tool_id]["execution"].append(edge["source"])
tool_assignments[tool_id]["llm"].append(edge["target"])
tool_assignments[tool_id] = {
"caller": edge["target"], # The LLM agent that calls the function
"executor": edge["source"], # The agent that executes the function
}
else:
print(f"Warning: Tool {tool_id} already assigned, skipping duplicate assignment")
else:
print(
colored(
f"Assigned tool ID {tool_id} not found in tools", "red"
)
)
print(colored(f"Assigned tool ID {tool_id} not found in tools", "red"))

# Now process WebSurferAgent tools
# Process WebSurferAgent tools
for edge in edges:
target_node = next(
(node for node in nodes if node["id"] == edge["target"]),
None
)
if target_node and target_node.get("data", {}).get("class_type") == "WebSurferAgent":
# Get the source node (usually a UserProxyAgent) for execution
source_node = next(
(node for node in nodes if node["id"] == edge["source"]),
None
)
if source_node:
# Get the web tool type from the node's data
web_tool = target_node.get("data", {}).get("web_tool", "browser_use")

# Add the tool registration to the generated code
# We don't need to create a mock function or add to tool_dict
# Instead, we'll handle this in the template by registering websurfer.tools
tool_id = f"websurfer_{target_node['id']}"
if tool_id not in tool_assignments:
tool_assignments[tool_id] = {
"execution": [],
"llm": [],
"is_websurfer": True, # Flag to indicate this is a WebSurferAgent tool
"web_tool": web_tool, # Store the web tool type
"websurfer_node_id": target_node["id"] # Store the WebSurferAgent node ID
"caller": target_node["id"], # WebSurferAgent calls the function
"executor": source_node["id"], # UserProxy executes the function
"is_websurfer": True,
"web_tool": web_tool,
"websurfer_node_id": target_node["id"]
}

if source_node["id"] not in tool_assignments[tool_id]["execution"]:
tool_assignments[tool_id]["execution"].append(source_node["id"])
if target_node["id"] not in tool_assignments[tool_id]["llm"]:
tool_assignments[tool_id]["llm"].append(target_node["id"])

return tool_assignments

Expand Down
1 change: 1 addition & 0 deletions api/agentok_api/templates/start_chat.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Start the conversation

{% if initial_chat_targets | length > 1 %}
Expand Down
2 changes: 0 additions & 2 deletions api/agentok_api/templates/tool.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

env_{{ tool.id }} = dotenv_values(os.path.join(current_dir, '{{ tool.id }}.env'))

print("Loading vars:", env_{{ tool.id }})

{%- for line in tool.code.split('\n') %}
{{ line }}
{%- endfor -%}
Expand Down
51 changes: 20 additions & 31 deletions api/agentok_api/templates/tool_binding.j2
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
{# Tool Binding #}
{%- if tool_assignments %}
{# Iterate over each tool_id in tool_assignments #}
{%- for tool_id, assignments in tool_assignments.items() %}

{%- if assignments.is_websurfer %}
# Register WebSurferAgent tools
{%- for node_id in assignments.execution %}
# Register all tools from WebSurferAgent to UserProxyAgent for execution
for tool in node_{{ assignments.websurfer_node_id }}.tools:
tool.register_for_execution(node_{{ node_id }})
{%- endfor %}
{%- else %}
{# Register LLM tools #}
{%- if assignments.llm -%}
# Register LLM tools to agents
{%- set tool = tool_dict[tool_id] %}
{%- for node_id in assignments.llm %}
node_{{ node_id }}.register_for_llm(
name="{{ tool['func_name'] }}",
description="{{ tool['description'] }}" # This field is only required when registering to LLM
)({{ tool['func_name'] }})
{%- endfor %}
{%- endif %}

{# Register Execution tools #}
{%- if assignments.execution -%}
# Register Execution tools to agents
{%- set tool = tool_dict[tool_id] %}
{%- for node_id in assignments.execution %}
node_{{ node_id }}.register_for_execution(name="{{ tool['func_name'] }}")({{ tool['func_name'] }})
{%- endfor %}
{%- endif -%}
{%- endif %}
{%- for tool_id, assignment in tool_assignments.items() %}
{% if assignment.get('is_websurfer') %}
# Register WebSurfer tools
autogen.register_function(
f=websurfer.tools.{{ assignment.web_tool }},
caller={{ assignment.caller }},
executor={{ assignment.executor }},
description="Web browsing capability for the WebSurfer agent"
)
{% else %}
{% set tool = tool_dict[tool_id] %}
# Register tool: {{ tool.name }}
autogen.register_function(
f={{ tool.func_name }},
caller=node_{{ assignment.caller }},
executor=node_{{ assignment.executor }},
name="{{ tool.func_name }}",
description="""{{ tool.description }}"""
)

{% endif %}
{%- endfor -%}
{%- endif -%}
4 changes: 2 additions & 2 deletions frontend/src/components/chat/message-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const MessageBubble = ({ chat, message, className }: MessageBubbleProps) => {
} else if (message.sender) {
messageHeader = (
<div className="chat-header flex items-end gap-2 text-xs text-muted-foreground font-semibold">
<div className="flex items-center gap-1">
<div className="flex items-center gap-1 overflow-x-hidden max-w-full">
{message.sender}
{message.receiver && (
<>
Expand Down Expand Up @@ -215,7 +215,7 @@ const MessageBubble = ({ chat, message, className }: MessageBubbleProps) => {
)}
</div>
<div
className={`relative group rounded-md p-2 text-sm break-word word-wrap overflow-x-hidden`}
className={`relative group rounded-md p-2 text-sm break-word word-wrap overflow-x-auto`}
>
{message.content ? (
<Markdown>{message.content}</Markdown>
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/components/flow/config/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ export const UserConfig = ({ nodeId, data }: any) => {
{ value: 'TERMINATE', label: 'On Terminate' },
]}
/>
<GenericOption
type="check"
nodeId={nodeId}
data={data}
name="enable_code_execution"
label="Enable Code Execution"
/>
</ConversableAgentConfig>
);
};

0 comments on commit 321aa1f

Please sign in to comment.