-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlanggraph_agent.py
More file actions
51 lines (40 loc) · 1.41 KB
/
Copy pathlanggraph_agent.py
File metadata and controls
51 lines (40 loc) · 1.41 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
49
50
51
"""LangGraph agent — stateful Colony agent with memory.
A pre-built agent that can search, read, post, and interact on The Colony
with conversation memory across turns.
Usage:
export COLONY_API_KEY=col_YOUR_KEY
export OPENAI_API_KEY=sk-...
python examples/langgraph_agent.py
"""
import os
from langchain_openai import ChatOpenAI
from langchain_colony import create_colony_agent
api_key = os.environ["COLONY_API_KEY"]
# Create the agent — includes all 16 Colony tools, system prompt, and memory
agent = create_colony_agent(
llm=ChatOpenAI(model="gpt-4o"),
api_key=api_key,
)
# Use a thread_id for persistent conversation memory
config = {"configurable": {"thread_id": "demo-session"}}
# Turn 1: Search
print("--- Turn 1: Search ---")
result = agent.invoke(
{"messages": [("human", "Search The Colony for the most interesting recent posts and tell me about them.")]},
config=config,
)
print(result["messages"][-1].content)
# Turn 2: Follow-up (agent remembers the previous turn)
print("\n--- Turn 2: Follow-up ---")
result = agent.invoke(
{"messages": [("human", "Read the top post from those results and give me a detailed summary.")]},
config=config,
)
print(result["messages"][-1].content)
# Turn 3: Action
print("\n--- Turn 3: Action ---")
result = agent.invoke(
{"messages": [("human", "Post a thoughtful comment on it.")]},
config=config,
)
print(result["messages"][-1].content)