-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbasic_agent.py
More file actions
34 lines (24 loc) · 965 Bytes
/
basic_agent.py
File metadata and controls
34 lines (24 loc) · 965 Bytes
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
"""Basic agent — identical LangChain code with @dura for durability.
This is a standard LangChain agent using create_agent. The only DuraLang
addition is @dura on the function. Every LLM call and tool call inside
becomes a Temporal Activity — automatically retried, heartbeated, and durable.
"""
import asyncio
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_core.messages import HumanMessage
from duralang import dura, dura_agent
@dura
async def research_agent(messages: list) -> list:
agent = dura_agent(
model="claude-sonnet-4-6",
tools=[TavilySearchResults(max_results=3)],
)
result = await agent.ainvoke({"messages": messages})
return result["messages"]
async def main():
result = await research_agent(
[HumanMessage(content="What are the latest developments in AI agents?")]
)
print(result[-1].content)
if __name__ == "__main__":
asyncio.run(main())