Skip to content
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
8 changes: 8 additions & 0 deletions libs/langchain/langchain/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,11 +1428,19 @@ def _perform_agent_action(
if return_direct:
tool_run_kwargs["llm_prefix"] = ""
# We then call the tool on the tool input to get an observation
# Get tool_call_id if exists for content_and_artifact
tool_call_id = (
agent_action.tool_call_id
if hasattr(agent_action, "tool_call_id")
else None
)

observation = tool.run(
agent_action.tool_input,
verbose=self.verbose,
color=color,
callbacks=run_manager.get_child() if run_manager else None,
tool_call_id=tool_call_id,
**tool_run_kwargs,
)
else:
Expand Down
4 changes: 4 additions & 0 deletions libs/langchain/langchain/agents/format_scratchpad/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def _create_tool_message(
"""
if not isinstance(observation, str):
try:
# if observation is already a ToolMessage, just update name and return it
if isinstance(observation, ToolMessage):
observation.additional_kwargs["name"] = agent_action.tool
return observation
content = json.dumps(observation, ensure_ascii=False)
except TypeError:
content = str(observation)
Expand Down
Loading