-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (34 loc) · 1.2 KB
/
Copy pathmain.py
File metadata and controls
43 lines (34 loc) · 1.2 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
"""Run the LangSmith tracing chat sample (Graph API).
Single-process driver: starts a Worker, executes the Workflow once, prints
the result, then shuts down. Requires ANTHROPIC_API_KEY and LANGCHAIN_API_KEY.
"""
import asyncio
import os
from temporalio.client import Client
from temporalio.contrib.langgraph import LangGraphPlugin
from temporalio.contrib.langsmith import LangSmithPlugin
from temporalio.worker import Worker
from langgraph_plugin.graph_api.langsmith_tracing.workflow import (
ChatWorkflow,
make_chat_graph,
)
async def main() -> None:
client = await Client.connect(
os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"),
plugins=[LangSmithPlugin(add_temporal_runs=True)],
)
async with Worker(
client,
task_queue="langgraph-langsmith",
workflows=[ChatWorkflow],
plugins=[LangGraphPlugin(graphs={"chat": make_chat_graph()})],
):
result = await client.execute_workflow(
ChatWorkflow.run,
"What is the meaning of life?",
id="langsmith-chat-workflow",
task_queue="langgraph-langsmith",
)
print(f"Response: {result}")
if __name__ == "__main__":
asyncio.run(main())