-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmulti_model.py
More file actions
38 lines (26 loc) · 1.06 KB
/
multi_model.py
File metadata and controls
38 lines (26 loc) · 1.06 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
"""Multi-model — same agent code, different LLM providers."""
import asyncio
from langchain_core.messages import HumanMessage
from duralang import dura, dura_agent
@dura
async def chat_agent(messages: list, provider: str = "anthropic") -> list:
"""Agent that works with any LLM provider."""
models = {
"anthropic": "claude-sonnet-4-6",
"openai": "gpt-4o",
}
model = models.get(provider)
if model is None:
raise ValueError(f"Unknown provider: {provider}")
agent = dura_agent(model=model)
result = await agent.ainvoke({"messages": messages})
return result["messages"]
async def main():
question = [HumanMessage(content="What is 2 + 2?")]
# Same agent, different providers — each becomes its own Temporal workflow
anthropic_result = await chat_agent(question, provider="anthropic")
print(f"Anthropic: {anthropic_result[-1].content}")
openai_result = await chat_agent(question, provider="openai")
print(f"OpenAI: {openai_result[-1].content}")
if __name__ == "__main__":
asyncio.run(main())