Your First Agent
In shortBuild and run a minimal 10xGraph graph that calls a real language model.
- 2 min read
- 7 sections
- Updated
- v0.9.2
- Markdown
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
- 10xGraph installed:
pip install 10xgraph - A language model API key (this example uses Google Gemini)
Set your API key:
export GOOGLE_API_KEY=your-api-keyThe graph
Create first_agent.py:
from tenxgraph.core.graph import Agent, StateGraph, ToolNode
from tenxgraph.core.state import AgentState
from tenxgraph.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 tenxgraph.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.pyExpected output (the exact words will vary):
The capital of France is Paris.What happened
sequenceDiagram
participant Script as first_agent.py
participant App as compiled app
participant Agent as Agent node
participant LLM as Language model
Script->>App: invoke(messages)
App->>Agent: run with AgentState
Agent->>LLM: send message
LLM-->>Agent: assistant reply
Agent-->>App: new Message
App-->>Script: result messages
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 tenxgraph.core.graph import Agent, StateGraph
from tenxgraph.core.state import AgentState, Message
from tenxgraph.utils import ENDWhat 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.
Last updated for v0.9.2Edit this page on GitHubReport an issue