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

[Core]: On Tool End Obersvation Casting Fix #18798

Merged
merged 10 commits into from
Mar 11, 2024

Conversation

keenborder786
Copy link
Contributor

Fixes the following issue #18760 raised by @eyurtsev

Copy link

vercel bot commented Mar 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 11, 2024 2:55pm

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. Ɑ: Runnables Related to Runnables 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Mar 8, 2024
Copy link
Collaborator

@eyurtsev eyurtsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might break a bunch of user code -- I'm going to scope out how to do this without introducing breaking changes

@keenborder786
Copy link
Contributor Author

okay, please let me know about the scope so I can integrate that within this PR. Thank you. @eyurtsev

@eyurtsev
Copy link
Collaborator

eyurtsev commented Mar 8, 2024

Keep PR open for now in case we decide to make a breaking here

@eyurtsev
Copy link
Collaborator

eyurtsev commented Mar 8, 2024

OK I think we can actually do this! It's a breaking change, but not one that I think will affect many users, and likely better to do this than to implement a work-around.

The remaining changes we need to make:

  1. git grep on_tool_end across the code base to find all tracer/callback handlers
  2. update the type signature from str to Any
  3. Add a cast to string inside the handler itself
    def on_tool_end(self, output: str, *, run_id: UUID, **kwargs: Any) -> Run:
        """End a trace for a tool run."""

to

    def on_tool_end(self, output: Any, *, run_id: UUID, **kwargs: Any) -> Run:
        """End a trace for a tool run."""
        output = str(output) # Cast to maintain logic unchanged

--

We can then follow up with another PR to actually fix astream_events:

  1. Add a unit test that includes the snippet of code I posted in the original issue -- goes here:
  2. Remove the cast to str in BaseTracer on_tool_end (that this PR will introduce)
    def on_tool_end(self, output: str, *, run_id: UUID, **kwargs: Any) -> Run:
  3. Celebrate!

@eyurtsev eyurtsev self-assigned this Mar 8, 2024
@adreo00
Copy link
Contributor

adreo00 commented Mar 8, 2024

@keenborder786 @eyurtsev looks like the same str casting appears elsewhere (in the arun method). Should that be lumped into this fix as well?

str(observation), color="red", name=self.name, **kwargs

and

str(observation), color=color, name=self.name, **kwargs

@eyurtsev
Copy link
Collaborator

eyurtsev commented Mar 8, 2024

Yeah we should get both sync and async methods good catch @adreo00

@eyurtsev
Copy link
Collaborator

eyurtsev commented Mar 8, 2024

@keenborder786 let me know if you're OK taking this on or want me to commandeer! Would be nice to merge a fix next week :)

@keenborder786
Copy link
Contributor Author

keenborder786 commented Mar 8, 2024 via email

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Mar 9, 2024
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Mar 9, 2024
@keenborder786
Copy link
Contributor Author

@eyurtsev please review.

@keenborder786
Copy link
Contributor Author

keenborder786 commented Mar 9, 2024

I will create the second PR for tests that you have mentioned after you have given a green light for this one..

@eyurtsev
Copy link
Collaborator

eyurtsev commented Mar 9, 2024

Looks good! On mobile right now, so won't merge until at my laptop later tonight.

@eyurtsev
Copy link
Collaborator

Had no time over the weekend, taking a look now

@eyurtsev eyurtsev self-requested a review March 11, 2024 14:31
@eyurtsev eyurtsev merged commit 43db4cd into langchain-ai:master Mar 11, 2024
97 checks passed
keenborder786 added a commit to keenborder786/langchain that referenced this pull request Mar 11, 2024
bechbd pushed a commit to bechbd/langchain that referenced this pull request Mar 29, 2024
This PR updates the on_tool_end handlers to return the raw output from the tool instead of casting it to a string. 

This is technically a breaking change, though it's impact is expected to be somewhat minimal. It will fix behavior in `astream_events` as well.

Fixes the following issue langchain-ai#18760 raised by @eyurtsev

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
gkorland pushed a commit to FalkorDB/langchain that referenced this pull request Mar 30, 2024
This PR updates the on_tool_end handlers to return the raw output from the tool instead of casting it to a string. 

This is technically a breaking change, though it's impact is expected to be somewhat minimal. It will fix behavior in `astream_events` as well.

Fixes the following issue langchain-ai#18760 raised by @eyurtsev

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
eyurtsev added a commit that referenced this pull request Apr 2, 2024
…l_end (#18932)

This PR completes work for PR #18798 to expose raw tool output in
on_tool_end.

Affected APIs:
* astream_log
* astream_events
* callbacks sent to langsmith via langsmith-sdk
* Any other code that relies on BaseTracer!

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
marlenezw pushed a commit to marlenezw/langchain that referenced this pull request Apr 2, 2024
…l_end (langchain-ai#18932)

This PR completes work for PR langchain-ai#18798 to expose raw tool output in
on_tool_end.

Affected APIs:
* astream_log
* astream_events
* callbacks sent to langsmith via langsmith-sdk
* Any other code that relies on BaseTracer!

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
hinthornw pushed a commit that referenced this pull request Apr 26, 2024
This PR updates the on_tool_end handlers to return the raw output from the tool instead of casting it to a string. 

This is technically a breaking change, though it's impact is expected to be somewhat minimal. It will fix behavior in `astream_events` as well.

Fixes the following issue #18760 raised by @eyurtsev

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
hinthornw pushed a commit that referenced this pull request Apr 26, 2024
…l_end (#18932)

This PR completes work for PR #18798 to expose raw tool output in
on_tool_end.

Affected APIs:
* astream_log
* astream_events
* callbacks sent to langsmith via langsmith-sdk
* Any other code that relies on BaseTracer!

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: Runnables Related to Runnables size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants