Your first agent
This page builds a working agent backed by a real language model. You will write the graph, run it in Python, and see a response.
What you need
- AgentFlow installed:
pip install 10xscale-agentflow - A language model API key (this example uses Google Gemini)
Set your API key:
export GOOGLE_API_KEY=your-api-key
The graph
Create first_agent.py:
from agentflow.core.graph import Agent, StateGraph, ToolNode
from agentflow.core.state import AgentState
from agentflow.utils import END
# Create the agent node backed by a language model
agent = Agent(
model="google/gemini-2.5-flash",
system_prompt=[
{
"role": "system",
"content": "You are a helpful assistant. Answer questions clearly and concisely.",
}
],
)
# Build the graph
graph = StateGraph(AgentState)
graph.add_node("assistant", agent)
graph.set_entry_point("assistant")
graph.add_edge("assistant", END)
app = graph.compile()
Run it
Add the invocation code at the bottom of first_agent.py:
from agentflow.core.state import Message
result = app.invoke(
{"messages": [Message.text_message("What is the capital of France?")]},
config={"thread_id": "beginner-demo-1"},
)
print(result["messages"][-1].text())
Run the file:
python first_agent.py
Expected output (the exact words will vary):
The capital of France is Paris.
What happened
app.invokeadds your message toAgentState.context.- The graph routes to the
assistantnode. Agentsends the conversation to the language model.- The model returns a reply, which becomes an assistant
Message. - The graph reaches
ENDand returns the updated state.
The thread_id in config groups this conversation. Every call with the same thread_id will eventually share history once you add a checkpointer.
Key imports
from agentflow.core.graph import Agent, StateGraph
from agentflow.core.state import AgentState, Message
from agentflow.utils import END
What you learned
Agentwraps a language model as a graph node.StateGraphwires the node into a runnable app.app.invokeruns the graph and returns updated state.- A
thread_idinconfigidentifies the conversation.
Next step
Give the agent something it can do — add a tool.