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

Custom tools(implemented in "Subclass Basetool" approach) cannot access to state via run_manager #1777

Open
5 tasks done
humbroll opened this issue Sep 20, 2024 · 0 comments

Comments

@humbroll
Copy link

humbroll commented Sep 20, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

class GooglePlacesTool(BaseTool):
    """Tool that queries the Google places API."""

    name: str = "google_places"
    description: str = (
        "A tool that queries the Google Places API. "
        "Useful for finding places based on a search query. "
        "This tool can help validate addresses or discover locations "
        "from ambiguous text inputs. "
        "Input should be a search query string."
    )
    api_wrapper: GooglePlacesAPIWrapper = Field(default_factory=GooglePlacesAPIWrapper)  # type: ignore[arg-type]
    args_schema: Type[BaseModel] = GooglePlacesSchema


    def _run(
        self,
        query: str,
        run_manager: Optional[CallbackManagerForToolRun] = None,
    ) -> str:
        logger.debug(f"RunManager has state?: {hasattr(run_manager, 'state')}")

        # Run the original tool logic
        result = self.api_wrapper.run(query)

        return result

Error Message and Stack Trace (if applicable)

RunManager has state?: False

Description

How can I access state in a custom tool using the "Subclass Basetool" approach?

System Info

$ pip freeze | grep langchain langchain==0.3.0 langchain-anthropic==0.1.23 langchain-cohere==0.2.4 langchain-community==0.3.0 langchain-core==0.3.0 langchain-experimental==0.0.65 langchain-google-community==2.0.0 langchain-openai==0.2.0 langchain-text-splitters==0.3.0 langchainhub==0.1.21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant