Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PY] fix: #1705 - Output of multiple calls to same tool are overwritten #2228

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/packages/ai/teams/ai/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ async def run(
# Set output for action call
if command.action_id:
loop = True
state.temp.action_outputs[command.action_id] = output or ""
if not command.action in state.temp.action_outputs: state.temp.action_outputs[command.action] = {}
state.temp.action_outputs[command.action][command.action_id] = output or ""
else:
loop = len(output) > 0
state.temp.action_outputs[command.action] = output
Expand Down
23 changes: 13 additions & 10 deletions python/packages/ai/teams/ai/planners/assistants_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,17 @@ async def _submit_action_results(self, state: TurnState) -> Plan:

# Map the action outputs to tool outputs
action_outputs = state.temp.action_outputs
tool_map = state.get(SUBMIT_TOOL_OUTPUTS_MAP)
tool_map : dict[str,list] = state.get(SUBMIT_TOOL_OUTPUTS_MAP)
tool_outputs: List[ToolOutput] = []

for action in action_outputs:
output = action_outputs[action]
if tool_map:
tool_call_id = tool_map[action] if action in tool_map else None
if tool_call_id is not None:
# Add required output only
tool_outputs.append(ToolOutput(tool_call_id=tool_call_id, output=output))
if tool_map:
for action in action_outputs:
if action in tool_map:
for tool_call_id in tool_map[action]:
output = action_outputs[action][tool_call_id] if tool_call_id in action_outputs[action] else None
if output is not None:
# Add required output only
tool_outputs.append(ToolOutput(tool_call_id=tool_call_id, output=output))

# Submit the tool outputs
if assistants_state.thread_id and assistants_state.run_id:
Expand Down Expand Up @@ -337,12 +338,14 @@ async def _wait_for_run(

def _generate_plan_from_tools(self, state: TurnState, required_action: RequiredAction) -> Plan:
plan = Plan()
tool_map: Dict = {}
tool_map: dict[str,list] = {}
for tool_call in required_action.submit_tool_outputs.tool_calls:
tool_map[tool_call.function.name] = tool_call.id
if not tool_call.function.name in tool_map : tool_map[tool_call.function.name] = []
tool_map[tool_call.function.name].append(tool_call.id)
plan.commands.append(
PredictedDoCommand(
action=tool_call.function.name,
action_id=tool_call.id,
parameters=json.loads(tool_call.function.arguments),
)
)
Expand Down
Loading