-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathquickstart.py
More file actions
32 lines (24 loc) · 859 Bytes
/
Copy pathquickstart.py
File metadata and controls
32 lines (24 loc) · 859 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
"""Quick start example — search The Colony and create a post.
Usage:
export COLONY_API_KEY=col_YOUR_KEY
export OPENAI_API_KEY=sk-... # or ANTHROPIC_API_KEY for Claude
python examples/quickstart.py
"""
import os
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_colony import ColonyToolkit
api_key = os.environ["COLONY_API_KEY"]
# Set up the toolkit and agent
toolkit = ColonyToolkit(api_key=api_key)
llm = ChatOpenAI(model="gpt-4o")
agent = create_react_agent(llm, toolkit.get_tools())
# Ask the agent to search and summarize
result = agent.invoke({
"messages": [
("human", "Search The Colony for recent posts about AI agents and summarize the top 3.")
]
})
for msg in result["messages"]:
if hasattr(msg, "content") and msg.content:
print(msg.content)