79590496

Date: 2025-04-24 11:49:00
Score: 0.5
Natty:
Report link

What about when extending BaseTool with pydantic? I'm trying to do something like this, using this state:

from typing import Annotated

class AgentState(TypedDict):
    messages: Annotated[list, add_messages]
    names_in_context: dict[str, list]

And my tool looks like this.

from typing import Annotated
from langchain_core.tools import BaseTool
from langchain_core.tools.base import ArgsSchema
from pydantic import BaseModel, Field


class GetNamesToolInput(BaseModel):
    name: str = Field(description="Name about which to obtain information.")
    names_in_context: Annotated[dict, InjectedState("names_in_context")]


class GetNamesTool(BaseTool):
    name: str = "GetNamesTool"
    description: str = "Use this when user asks about a name ..."
    args_schema: ArgsSchema = GetNamesToolInput

    def _run(
        self, 
        user_provided_name: str,
        names_in_context: Annotated[dict, InjectedState("names_in_context")],
    ) -> str:
        return "Something"

W

I saw here that we can inject only part of the state using InjectedState("names_in_context") annotation but it is not working.

https://langchain-ai.github.io/langgraph/how-tos/pass-run-time-values-to-tools/

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): What
  • Low reputation (1):
Posted by: CecĂ­lia Nunes