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

Add assistant.tool_choice parameter to force the Assistant to use a certain Tool function #738

Closed
andreibondarev opened this issue Aug 24, 2024 · 0 comments · Fixed by #744
Assignees
Labels
assistants Related to Langchain::Assistant class enhancement New feature or request

Comments

@andreibondarev
Copy link
Collaborator

andreibondarev commented Aug 24, 2024

Currently the Assistant optionally picks a tool whenever it "thinks" it's appropriate to do so (tool_choice = "auto"). There are instances when you want the Assistant to use a specific tool 100% of the time (tool_choice = { "tool_name" }). This ticket was inspired by the following discussion: #733

Proposed changes:

  • Introduce the @tool_choice instance variable that could be set during the initialization assistant = Langchain::Assistant.new(tool_choice: ...,) or after: assistant.tool_choice = "...".
  • @tool_choice is used here, here and here.

If you take any of the built-in tools, you can see a list of that Tool's functions:

Langchain::Tool::NewsRetriever.function_schemas.to_openai_format.map { |h| h.dig(:function, :name) }
=> ["langchain_tool_news_retriever__get_everything", "langchain_tool_news_retriever__get_top_headlines", "langchain_tool_news_retriever__get_sources"]

This should be the value we're setting the tool_choice to:

assistant.tool_choice = "langchain_tool_news_retriever__get_sources"
@andreibondarev andreibondarev added enhancement New feature or request assistants Related to Langchain::Assistant class labels Aug 24, 2024
@andreibondarev andreibondarev self-assigned this Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assistants Related to Langchain::Assistant class enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant