Skip to content

Commit

Permalink
filter double tool calls in interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonalaird committed Jan 18, 2025
1 parent e12d6b7 commit 3b1ccb6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion vision_agent/agent/vision_agent_planner_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,25 @@ def create_hil_response(
except Exception:
continue

# There's a chance that the same tool is called multiple times with the same inputs
# in the interaction. We want to remove duplicates to avoid redundancy by picking
# the last occurrence of the tool.
cleaned_content = []
seen_content = set()
for c in reversed(content):
if "request" in c and "function_name" in c["request"] and "files" in c:
key = (c["request"]["function_name"], hash(c["files"]))
if key in seen_content:
continue

seen_content.add(key)
cleaned_content.append(c)
else:
cleaned_content.append(c)

return AgentMessage(
role="interaction",
content="<interaction>" + json.dumps(content) + "</interaction>",
content="<interaction>" + json.dumps(cleaned_content) + "</interaction>",
media=None,
)

Expand Down

0 comments on commit 3b1ccb6

Please sign in to comment.