You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an example **LangGraph Python agent** using the **OpenAI LLM** to answer questions about cryptocurrencies.
3
+
## Overview
4
4
5
-
You can run this code locally and expand it to build your own Agent, as shown in this guide:
5
+
This is an example **LangGraph Python agent** using the **OpenAI LLM** to answer questions about cryptocurrencies. This agent is **A2A-compatible**.
6
+
7
+
You can run this code locally and extend it to build your own Agent, as shown in this guide:
6
8
7
9
-[Get Started with Python LangGraph agents](../../docs/langgraph-quick-start-py.md)
10
+
11
+
## What the Agent Does
12
+
13
+
This agent is a crypto-focused **single-node** chatbot that receives a message, calls an **OpenAI** model, and returns an assistant response.
14
+
15
+
## How It Works
16
+
17
+
### Nodes and Graphs
18
+
19
+
In LangGraph, a **graph** is a map of how your agent thinks and acts. It defines what steps the agent can take and how those steps connect.
20
+
21
+
Each **node** is one of those steps—for example:
22
+
23
+
- calling an AI model
24
+
- fetching data from an API
25
+
- deciding what to do next
26
+
27
+
When you build a LangGraph agent, you're basically creating a small workflow made of these nodes. The graph handles how messages move between them—so your agent can reason, make calls, and respond in a structured way.
28
+
29
+
In this example, there is only one node, which calls OpenAI.
30
+
31
+
### The Agent's Main Logic
32
+
33
+
The agent logic is defined in [`src/agent/graph.py`](src/agent/graph.py):
34
+
35
+
- The code imports the `langgraph.graph` and `langgraph.runtime` components for building and running the agent.
36
+
-`Context` is a class defining configurable parameters accessible to the runtime.
37
+
-`State` is a dataclass defining the agent's working memory (a list of message objects forming the conversation).
38
+
-`call_model` is a **node** responsible for interacting with the LLM (`gpt-4o-mini` from OpenAI). It receives the current conversation state and runtime context, sends the latest user message to the model, an updated message list that includes the assistant's response.
39
+
-`graph` defines the **graph**. `StateGraph` describes the workflow, with one node (`call_model`) that runs as soon as the graph starts. The `compile()` function finalizes the workflow into an executable runtime graph.
40
+
- The agent follows the **A2A protocol**, meaning it can receive and send structured conversational messages to other agents. The `State` and `Context` schemas make it interoperable with other A2A-compatible components
This is an example **LangGraph TypeScript agent** using the **OpenAI LLM** to answer questions about cryptocurrencies.
4
6
5
-
You can run this code locally and expand it to build your own agent, as shown in this guide:
7
+
You can run this code locally and extend it to build your own agent, as shown in this guide:
6
8
7
9
-[Get Started with TypeScript LangGraph agents](../../docs/langgraph-quick-start.md)
10
+
11
+
## What the Agent Does
12
+
13
+
This agent is a crypto-focused **single-node** chatbot that receives a message, calls an **OpenAI** model, and returns an assistant response.
14
+
15
+
## How It Works
16
+
17
+
### Nodes and Graphs
18
+
19
+
In LangGraph, a **graph** is a map of how your agent thinks and acts. It defines what steps the agent can take and how those steps connect.
20
+
21
+
Each **node** is one of those steps—for example:
22
+
23
+
- calling an AI model
24
+
- fetching data from an API
25
+
- deciding what to do next
26
+
27
+
When you build a LangGraph agent, you're basically creating a small workflow made of these nodes. The graph handles how messages move between them—so your agent can reason, make calls, and respond in a structured way.
28
+
29
+
In this example, there is only one node, which calls OpenAI.
30
+
31
+
### The Agent's Main Logic
32
+
33
+
The agent logic is defined in [`src/agent/graph.ts`](src/agent/graph.ts):
34
+
35
+
- The code imports key **LangChain** and **LangGraph** components.
36
+
-`callModel` is a **node** responsible for interacting with the LLM (`gpt-4o-mini` from OpenAI). It reads the current conversation from the graph state, sends the first user message to the model, and returns an assistant reply, updating the `messages` field of the state. The system prompt limits the agent to crypto-related answers only.
37
+
-`StateAnnotation` defines the shared state structure between nodes—typically a schema for messages, actions, and intermediate results.
38
+
-`route` is a router node that decides whether to continue querying or end the process—based on the state.
39
+
-`StateGraph` connects nodes, defining their execution order and dependencies. This example includes only one node—`callModel`.
40
+
-`compile()` is a function compiles the **graph** (`graph`) into a runnable agent processing input messages and updates the state through each step.
Copy file name to clipboardExpand all lines: agents/weather-agent/README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Weather Agent - Your First LangGraph Agent
1
+
# Weather Agent: Your First LangGraph Agent
2
2
3
3
A beginner-friendly agent that shows you how to build AI agents using **LangGraph** and **TypeScript**. This agent fetches real-time weather data and provides helpful recommendations.
4
4
@@ -160,10 +160,10 @@ The agent has two tools:
160
160
```
161
161
weather-agent/
162
162
├── src/
163
-
│ └── graph.ts # Main agent code (the whole agent in one file!)
164
-
├── .env # Your API keys (you create this)
165
-
├── .env.example # Template for .env
166
-
├── package.json # Dependencies
163
+
│ └── graph.ts # Main agent code (the whole agent in one file!)
Copy file name to clipboardExpand all lines: docs/README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,4 +7,6 @@ To quickly start building with LangGraph, see the following guides:
7
7
-[Get started with TypeScript LangGraph agents](langgraph-quick-start.md)
8
8
-[Get started with Python LangGraph agents](langgraph-quick-start-py.md)
9
9
10
+
**Note**: These guides focus on the essentials: how to deploy and test your agent locally. If you'd rather skip setup details and dive straight into building real-world agent logic, check out the [Weather Agent example](../agents/weather-agent).
Copy file name to clipboardExpand all lines: docs/langgraph-quick-start-py.md
+15-11Lines changed: 15 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
# Get started with Python LangGraph agents
1
+
# Get started with Python LangGraph Agents
2
2
3
3
## Overview
4
4
5
-
This explains how to quickly get started with creating[LangGraph agents](https://langchain-ai.github.io/langgraph/agents/overview/) with [A2A support](https://docs.langchain.com/langsmith/server-a2a) in **Python**.
5
+
This guide explains how to quickly get started with building[LangGraph agents](https://langchain-ai.github.io/langgraph/agents/overview/) with [A2A support](https://docs.langchain.com/langsmith/server-a2a) in **Python**.
6
6
7
-
You'll copy, run, and expand our example agent: [`agents/laggraph-quick-start-py`](../agents/langgraph-quick-start-py).
7
+
You'll copy, run, and extend our template: [`agents/laggraph-quick-start-py`](../agents/langgraph-quick-start-py). It's a **single-node** chatbot that answer questions about cryptocurrencies: receives a message, calls an **OpenAI** model, and returns an assistant response.
8
8
9
-
**Note**: This example uses **OpenAI** by default, but you can switch to a different LLM.
9
+
**Note**: This guide focuses on the essentials (how to deploy and test your agent locally) rather than on real-world agent logic.
10
10
11
11
## Prerequisites
12
12
@@ -16,7 +16,7 @@ Before you start, complete the following prerequisites:
16
16
-[Get a LangSmith API key](https://docs.langchain.com/langsmith/home).
17
17
-[Get an OpenAI API key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key).
18
18
19
-
## Step 1. Set up the example project
19
+
## Step 1. Set Up the Example Project
20
20
21
21
First, set up the example project:
22
22
@@ -60,7 +60,7 @@ First, set up the example project:
60
60
LANGSMITH_PROJECT=py-agent
61
61
LANGSMITH_TRACING=true
62
62
```
63
-
## Step 2. Run the agent locally
63
+
## Step 2. Run the Agent Locally
64
64
65
65
Now you can run the example agent locally:
66
66
@@ -247,7 +247,7 @@ Now you can run the example agent locally:
247
247
}
248
248
}'
249
249
```
250
-
If everything is fine, you'll receive a response including your propmt, assistant's reply, and other data:
250
+
If everything is fine, you'll receive a response including your prompt, assistant's reply, and other data:
251
251
252
252
```json
253
253
{
@@ -308,11 +308,15 @@ Now you can run the example agent locally:
308
308
309
309
6. In addition, you can check logs in [LangSmith](https://smith.langchain.com/studio): navigate to **Tracing Project** in the left menu and select your project. The logs will display data on all threads and runs (agent invocations).
310
310
311
-
## Step 3. Implement custom logic
311
+
## Step 3. Implement Custom Logic
312
312
313
-
After testing the example agent, you can proceed with implementing your custom logic.
313
+
The logic of the template agent is explained in its [README](../agents/langgraph-quick-start-py/README.md).
314
314
315
-
If you prefer a different LLM to OpenAI, adjust the example code accordingly and update the `.env` file and dependencies.
315
+
After testing the agent, you can proceed with implementing your custom logic:
316
+
- If you prefer a different LLM to OpenAI, adjust the example code accordingly and update the `.env` file and dependencies.
317
+
- Add new nodes—for example, a node calling a crypto API or a summarize node using another model.
318
+
- Integrate memory to store conversation history or facts across sessions.
319
+
- Customize the state: add fields for context like topics, confidence, or source URLs.
316
320
317
321
To learn more about LangGraph, use the following resources:
318
322
@@ -323,7 +327,7 @@ To learn more about LangGraph, use the following resources:
323
327
-[LangGraph Platform API Reference](https://langchain-ai.github.io/langgraph/cloud/reference/api/api_ref.html#tag/assistants/post/assistants/search): Explore the endpoints for interacting with agents
324
328
-[LangGraph Python SDK](https://langchain-ai.github.io/langgraph/cloud/reference/sdk/python_sdk_ref/): Install the SDK for interacting with the API
0 commit comments