Skip to content

Add langchain tool support #8292

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

Merged
merged 3 commits into from
Jun 2, 2025
Merged

Conversation

TomeHirata
Copy link
Collaborator

@TomeHirata TomeHirata commented May 29, 2025

Similar to how we support MCP, we support Langchain Tools by providing a conversion method from Langchain Tools to DSPy tool. I will follow up with a tutorial for the langchain tool usage with ReAct.

import dspy
from langchain_community.tools.yahoo_finance_news import YahooFinanceNewsTool
lm = dspy.LM(model='openai/gpt-4o-mini', max_tokens=10000, temperature = 1.0)
dspy.configure(lm=lm, cache=False)
react = dspy.ReAct("query -> result", tools=[dspy.Tool.from_langchain(YahooFinanceNewsTool())])
res = await react.acall(query="Any interesting news happen today?")
res.result

-> "Interesting news today includes discussions about Apple's competitive challenges against its peers in the tech sector and Elon Musk's announcement regarding the end of his role with DOGE, hinting at a shift in focus back to Tesla and its operations."

@okhat
Copy link
Collaborator

okhat commented Jun 2, 2025

LGTM we should merge this right after we finish releasing 2.6.25 correctly. Once that's out, anyone can merge. Don't wait for me.

@okhat okhat merged commit 23d0e89 into stanfordnlp:main Jun 2, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants