You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by shruthiR-fauna January 24, 2025
Checked other resources
I added a very descriptive title to this question.
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
Commit to Help
I commit to help with one of those options 👆
Example Code
fromtypingimportAnnotated, Any, Dict, List, Typefromlangchain_core.promptsimportChatPromptTemplatefromlangchain_core.runnablesimportchainfromlangchain_core.toolsimportBaseTool, InjectedToolArgfromlangchain_openaiimportChatOpenAIfrompydanticimportBaseModel, FieldclassRobotDogStateManager:
# Simulated state management for the robot dogdef__init__(self):
self.battery_level=100self.current_location=""classGoToObjectInput(BaseModel):
""" Input for going to an object, visible to the model """object: str=Field(description="The object to go to")
classGoToObjectTool(BaseTool):
name: str="go_to_object"description: str="Instruct the robot dog to go to a specific object"args_schema: Type[BaseModel] =GoToObjectInputdef_run(
self,
object: str,
# Use InjectedToolArg for arguments the model shouldn't seerobot_state: Annotated[RobotDogStateManager, InjectedToolArg],
battery_threshold: Annotated[float, InjectedToolArg] =20.0,
) ->str:
""" Go to an object, with additional context not visible to the model """# Check battery level before proceedingifrobot_state.battery_level<battery_threshold:
return (
f"Cannot go to {object}. Battery too low: {robot_state.battery_level}%"
)
# Update robot's locationrobot_state.current_location=objectreturnf"Successfully went to {object}"# Example usagedefmain():
# Create a shared state managerrobot_state=RobotDogStateManager()
robot_state.battery_level=10# Create the toolgo_to_object_tool=GoToObjectTool()
# Input and output schemas for the toolprint(f"Input schema for tool: {go_to_object_tool.get_input_schema().schema()}")
# Try to invoke the toolgo_to_object_tool.invoke({'object': 'kitchen', 'robot_state': robot_state})
if__name__=="__main__":
main()
Description
I'm trying to use the LangChain library to create an agent that can serve as the coding system for a robot dog. The minimal example provided above provides a toy example of the model I'm using.
I've created a tool go_to_object that can be bound to an LLM that supports tool calling. Two arguments to the tool can only be provided at runtime so they are annotated with the InjectedToolArg in the _run method.
However, when I call this tool with go_to_object_tool.invoke where I supply all the required args, I see the following error *** TypeError: GoToObjectTool._run() missing 1 required positional argument: 'robot_state'
I've spent a lot of time digging through the API and the docs. I think this exposes a bug in how tool_args and tool_kwargs are parsed.
System Info
System Information
OS: Linux
OS Version: #52~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Dec 9 15:00:52 UTC 2
Python Version: 3.10.12 (main, Jan 17 2025, 14:35:34) [GCC 11.4.0]
The text was updated successfully, but these errors were encountered:
dosubotbot
added
Ɑ: core
Related to langchain-core
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
labels
Jan 24, 2025
Discussed in #29411
Originally posted by shruthiR-fauna January 24, 2025
Checked other resources
Commit to Help
Example Code
Description
I'm trying to use the LangChain library to create an agent that can serve as the coding system for a robot dog. The minimal example provided above provides a toy example of the model I'm using.
I've created a tool
go_to_object
that can be bound to an LLM that supports tool calling. Two arguments to the tool can only be provided at runtime so they are annotated with theInjectedToolArg
in the_run
method.However, when I call this tool with
go_to_object_tool.invoke
where I supply all the required args, I see the following error*** TypeError: GoToObjectTool._run() missing 1 required positional argument: 'robot_state'
I've spent a lot of time digging through the API and the docs. I think this exposes a bug in how
tool_args
andtool_kwargs
are parsed.System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: