-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlangchain-agent.py
More file actions
48 lines (39 loc) · 1.5 KB
/
langchain-agent.py
File metadata and controls
48 lines (39 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
LangChain Research Agent — BrowseAI Dev Example
Drop BrowseAI Dev into a LangChain agent as a research tool.
The agent gets evidence-backed web research capabilities.
Usage:
pip install langchain-browseaidev langchain langchain-openai
python langchain-agent.py
"""
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_browseaidev import (
BrowseAIDevSearchTool,
BrowseAIDevAnswerTool,
BrowseAIDevExtractTool,
)
# BrowseAI Dev tools — agent gets evidence-backed research
tools = [
BrowseAIDevSearchTool(api_key="bai_xxx"), # Web search
BrowseAIDevAnswerTool(api_key="bai_xxx"), # Full research pipeline (verified)
BrowseAIDevExtractTool(api_key="bai_xxx"), # Page extraction
]
# Standard LangChain agent setup
llm = ChatOpenAI(model="gpt-4o")
prompt = ChatPromptTemplate.from_messages([
("system", """You are a research assistant. Use BrowseAI Dev tools to find
evidence-backed answers. Always cite your sources and mention the
confidence score. Never make claims without evidence."""),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Run
result = executor.invoke({
"input": "What are the top 3 JavaScript frameworks in 2025 and why?"
})
print("\n--- Result ---")
print(result["output"])