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[minor],openai[patch],langchain[patch]: Allow tool functions to input ToolCall / return ToolMessage #6005

Merged
merged 21 commits into from
Jul 15, 2024

Conversation

bracesproul
Copy link
Member

@bracesproul bracesproul commented Jul 8, 2024

TODO:

  • update tool return type to be: string default. ToolMessage if a tool call is passed in.
    • ideally: if tool call is passed and tool call id is passed, return ToolMessage, else return str

Followup PR will wrap all integrations with the createToolCall/createToolCallChunk func

Tools can now:

  • take ToolCall as an input.
  • return ToolMessage

Updated generics to reflect that.
Added a third generic to tool func wrapper if you want to specify for the input arg of the func field. (it will infer if no generics were prev passed)

Copy link

vercel bot commented Jul 8, 2024

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

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2024 9:13pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2024 9:13pm

@bracesproul bracesproul marked this pull request as ready for review July 8, 2024 22:15
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 8, 2024
@@ -197,7 +198,7 @@ abstract class BaseCallbackHandlerMethodsClass {
* Called at the end of a Tool run, with the tool output and the run ID.
*/
handleToolEnd?(
output: string,
output: string | ToolMessage,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be an any type -- a tool should be allowed to return anything, and we shouldn't be limiting the return type in anyway

Suggested change
output: string | ToolMessage,
output: any,

Copy link
Collaborator

Choose a reason for hiding this comment

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

How would we handle things that aren't a string or tool message? Type check and e.g. JSON.stringify?

@bracesproul bracesproul marked this pull request as draft July 10, 2024 21:32
@bracesproul bracesproul changed the title core[minor]: Allow tool functions to return ToolMessage core[minor]: Allow tool functions to input ToolCall / return ToolMessage Jul 12, 2024
@jacoblee93 jacoblee93 changed the title core[minor]: Allow tool functions to input ToolCall / return ToolMessage core[minor],openai[patch],langchain[patch]: Allow tool functions to input ToolCall / return ToolMessage Jul 15, 2024
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jul 15, 2024
@jacoblee93 jacoblee93 merged commit 39e03f7 into main Jul 15, 2024
44 checks passed
@jacoblee93 jacoblee93 deleted the brace/tools-return-tool-message branch July 15, 2024 21:20
@jacoblee93 jacoblee93 restored the brace/tools-return-tool-message branch July 16, 2024 01:01
@jacoblee93 jacoblee93 deleted the brace/tools-return-tool-message branch October 9, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants