Skip to content

Commit 6ec242a

Browse files
committed
Merge branch 'main' into feat_short_based_memory_agent
2 parents 83cb494 + 8a89678 commit 6ec242a

46 files changed

Lines changed: 659 additions & 567 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.env*
12
.env
23
.vscode
34
.idea

agents/base/langgraph_react_agent/Dockerfile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ WORKDIR /app
88
# UID 1001 is commonly used in OpenShift deployments
99
RUN groupadd -r appuser && useradd -r -u 1001 -g appuser appuser
1010

11-
# Copy requirements file first for better layer caching
12-
COPY requirements.txt .
11+
# Install uv for fast dependency management
12+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
1313

14-
# Install Python dependencies
15-
RUN pip install --no-cache-dir --upgrade pip && \
16-
pip install --no-cache-dir -r requirements.txt
14+
# Copy project files for dependency installation
15+
COPY pyproject.toml .
16+
COPY src/ ./src/
17+
18+
# Install the project and its dependencies using uv
19+
RUN uv pip install --system --no-cache .
1720

18-
# Copy the application code
21+
# Copy the application entrypoint
1922
COPY main.py .
20-
COPY src/ ./src/
2123

2224
# Change ownership of the app directory to the non-privileged user
2325
RUN chown -R appuser:appuser /app
@@ -33,5 +35,4 @@ ENV PORT=8080
3335
ENV PYTHONPATH=/app:/app/src
3436

3537
# Run the application
36-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
37-
38+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
<div style="text-align: center;">
22

33
![LangGraph Logo](/images/langgraph_logo.svg)
4+
45
# ReACT Agent
56

67
</div>
78

89
---
10+
911
## What this agent does
10-
General-purpose agent using a ReAct loop: it reasons and calls tools (e.g. search, math) step by step. Built with LangGraph and LangChain.
12+
13+
General-purpose agent using a ReAct loop: it reasons and calls tools (e.g. search, math) step by step. Built with
14+
LangGraph and LangChain.
1115

1216
---
17+
1318
### Preconditions:
14-
- You need to copy/paste .env file and change its values to yours
19+
20+
- You need to change .env.template file to .env
1521
- Decide what way you want to go `local` or `RH OpenShift Cluster` and fill needed values
1622
- use `./init.sh` that will add those values from .env to environment variables
1723

24+
Go to agent dir
1825

26+
```bash
27+
cd agents/base/langgraph_react_agent
28+
```
29+
30+
Change the name of .env file
1931

20-
Copy .env file
2132
```bash
22-
cp template.env agents/base/langgraph_react_agent/.env
33+
mv template.env .env
2334
```
2435

2536
#### Local
37+
2638
Edit the `.env` file with your local configuration:
2739

2840
```
@@ -33,6 +45,7 @@ CONTAINER_IMAGE=not-needed
3345
```
3446

3547
#### OpenShift Cluster
48+
3649
Edit the `.env` file and fill in all required values:
3750

3851
```
@@ -43,46 +56,47 @@ CONTAINER_IMAGE=quay.io/your-username/langgraph-react-agent:latest
4356
```
4457

4558
**Notes:**
59+
4660
- `API_KEY` - contact your cluster administrator
4761
- `BASE_URL` - should end with `/v1`
4862
- `MODEL_ID` - contact your cluster administrator
4963
- `CONTAINER_IMAGE` - full image path where the agent container will be pushed and pulled from.
5064
The image is built locally, pushed to this registry, and then deployed to OpenShift.
5165

5266
Format: `<registry>/<namespace>/<image-name>:<tag>`
53-
54-
Examples:
55-
- Quay.io: `quay.io/your-username/langgraph-react-agent:latest`
56-
- Docker Hub: `docker.io/your-username/langgraph-react-agent:latest`
57-
- GHCR: `ghcr.io/your-org/langgraph-react-agent:latest`
5867

59-
Go to agent dir
60-
```bash
61-
cd agents/base/langgraph_react_agent
62-
```
68+
Examples:
69+
- Quay.io: `quay.io/your-username/langgraph-react-agent:latest`
70+
- Docker Hub: `docker.io/your-username/langgraph-react-agent:latest`
71+
- GHCR: `ghcr.io/your-org/langgraph-react-agent:latest`
6372

6473
Create and activate a virtual environment (Python 3.12) in this directory using [uv](https://docs.astral.sh/uv/):
74+
6575
```bash
6676
uv venv --python 3.12
6777
source .venv/bin/activate
6878
```
79+
6980
(On Windows: `.venv\Scripts\activate`)
7081

7182
Make scripts executable
83+
7284
```bash
7385
chmod +x init.sh
7486
```
7587

7688
Add to values from .env to environment variables
89+
7790
```bash
78-
./init.sh
91+
source ./init.sh
7992
```
8093

8194
---
8295

8396
## Local usage (Ollama + LlamaStack Server)
8497

8598
Create package with agent and install it to venv
99+
86100
```bash
87101
uv pip install -e .
88102
```
@@ -92,75 +106,93 @@ uv pip install ollama
92106
```
93107

94108
Install app from Ollama site or via Brew
109+
95110
```bash
96111
#brew install ollama
97112
# or
98113
curl -fsSL https://ollama.com/install.sh | sh
99114
```
100115

101116
Pull Required Model
117+
102118
```bash
103119
ollama pull llama3.2:3b
104120
```
105121

106122
Start Ollama Service
123+
107124
```bash
108125
ollama serve
109126
```
110-
>**Keep this terminal open!**\
127+
128+
> **Keep this terminal open!**\
111129
> Ollama needs to keep running.
112130
113131
Start LlamaStack Server
132+
114133
```bash
115134
llama stack run ../../../run_llama_server.yaml
116135
```
136+
117137
> **Keep this terminal open** - the server needs to keep running.\
118138
> You should see output indicating the server started on `http://localhost:8321`.
119139
120-
Run the example:
140+
Run the example:
141+
121142
```bash
122143
uv run examples/execute_ai_service_locally.py
123144
```
124145

125146
# Deployment on RedHat OpenShift Cluster
147+
126148
Login to OC
149+
127150
```bash
128151
oc login -u "login" -p "password" https://super-link-to-cluster:111
129152
```
130-
Login ex. Docker
153+
154+
Login ex. Docker
155+
131156
```bash
132157
docker login -u='login' -p='password' quay.io
133158
```
134159

135160
Make deploy file executable
161+
136162
```bash
137163
chmod +x deploy.sh
138164
```
139165

140166
Build image and deploy Agent
167+
141168
```bash
142169
./deploy.sh
143170
```
144171

145172
This will:
173+
146174
- Create Kubernetes secret for API key
147175
- Build and push the Docker image
148176
- Deploy the agent to OpenShift
149177
- Create Service and Route
150178

151179
COPY the route URL and PASTE into the CURL below
180+
152181
```bash
153182
oc get route langgraph-react-agent -o jsonpath='{.spec.host}'
154183
```
155184

156185
Send a test request:
186+
157187
```bash
158188
curl -X POST https://<YOUR_ROUTE_URL>/chat \
159189
-H "Content-Type: application/json" \
160190
-d '{"message": "What is the best company? Answer with the first correct answer."}'
161191
```
162192

163193
## Agent-Specific Documentation
194+
164195
Each agent has detailed documentation for setup and deployment:
196+
165197
- https://ollama.com/
166198
- https://formulae.brew.sh/formula/ollama#default

agents/base/langgraph_react_agent/examples/execute_ai_service_locally.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from os import getenv
2+
13
from _interactive_chat import InteractiveChat
24
from ai_service import ai_stream_service
3-
from langgraph_react_agent_base.utils import get_env_var
45

56

67
class SimpleContext:
@@ -19,8 +20,8 @@ def get_headers(self):
1920
return {}
2021

2122

22-
base_url = get_env_var("BASE_URL")
23-
model_id = get_env_var("MODEL_ID")
23+
base_url = getenv("BASE_URL")
24+
model_id = getenv("MODEL_ID")
2425

2526
# Ensure base_url ends with /v1 if provided
2627
if base_url and not base_url.endswith("/v1"):
Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,64 @@
11
#!/bin/bash
2-
# Usage:
3-
# ./init.sh
42
#
5-
# Prerequisites:
6-
# - oc CLI installed and logged in to OpenShift cluster
7-
# - docker installed
8-
# - Access to container registry (e.g., Quay.io)
3+
# init.sh - Environment bootstrap for the LangGraph ReAct Agent
94
#
5+
# Loads environment variables from the .env file located next to this script,
6+
# validates that all required variables (API_KEY, BASE_URL, MODEL_ID,
7+
# CONTAINER_IMAGE) are set, and ensures the shared milvus_data directory
8+
# exists at the repository root.
109

11-
set -e
12-
13-
source .env && echo "Environment variables loaded from .env file"
14-
15-
if [ -z "$API_KEY" ]; then
16-
echo "API_KEY not set, check .env file"
17-
exit 1
18-
fi
10+
#
11+
# Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
12+
#
1913

20-
if [ -z "$BASE_URL" ]; then
21-
echo "BASE_URL not set, check .env file"
22-
exit 1
23-
fi
14+
# Resolve the directory containing this script (works when sourced or executed)
15+
# BASH_SOURCE works in bash; ${(%):-%x} is the zsh equivalent
16+
AGENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")" && pwd)"
17+
REPO_ROOT="$AGENT_DIR/../../.."
18+
ENV_FILE="$AGENT_DIR/.env"
2419

25-
if [ -z "$MODEL_ID" ]; then
26-
echo "MODEL_ID not set, check .env file"
27-
exit 1
28-
fi
20+
# 1. Load .env, export variables, and collect their names for validation
21+
ENV_VARS=()
2922

30-
if [ -z "$CONTAINER_IMAGE" ]; then
31-
echo "CONTAINER_IMAGE not set, check .env file"
32-
exit 1
23+
if [ -f "$ENV_FILE" ]; then
24+
while IFS= read -r line || [ -n "$line" ]; do
25+
line="${line//$'\r'/}"
26+
line="${line#"${line%%[![:space:]]*}"}"
27+
[[ -z "$line" || "$line" == \#* ]] && continue
28+
export "$line"
29+
ENV_VARS+=("${line%%=*}")
30+
done < "$ENV_FILE"
31+
echo "Environment variables loaded from $ENV_FILE"
32+
else
33+
echo "ERROR: .env file not found at $ENV_FILE"
34+
return 1 2>/dev/null || exit 1
3335
fi
3436

35-
# Get the directory where the script is located
36-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
37-
38-
# Get the root directory of the repository (3 levels up from script)
39-
ROOT_DIR="$(cd "$SCRIPT_DIR/../../.." && pwd)"
37+
# 2. Validate every variable found in .env
38+
for var_name in "${ENV_VARS[@]}"; do
39+
var_value=$(eval echo "\$$var_name")
40+
if [ -z "$var_value" ]; then
41+
echo " ERROR: $var_name is empty. Check your .env file."
42+
return 1 2>/dev/null || exit 1
43+
fi
44+
local_lower=$(echo "$var_name" | tr '[:upper:]' '[:lower:]')
45+
if [[ "$local_lower" == *password* || "$local_lower" == *apikey* || "$local_lower" == *api_key* || "$local_lower" == *secret* || "$local_lower" == *token* ]]; then
46+
echo " $var_name=****"
47+
else
48+
echo " $var_name=$var_value"
49+
fi
50+
done
4051

41-
# Copy utils.py to the destination
42-
cp "$ROOT_DIR/utils.py" "$SCRIPT_DIR/src/langgraph_react_agent_base/" && echo "Utils.py copied to destination"
52+
# 3. Ensure milvus_data directory exists at repo root
53+
MILVUS_DIR="$REPO_ROOT/milvus_data"
4354

44-
echo "Agent initialized successfully"
55+
if [ -d "$MILVUS_DIR" ]; then
56+
echo "milvus_data directory exists in root folder"
57+
else
58+
if mkdir -p "$MILVUS_DIR"; then
59+
echo "Created milvus_data directory at: $MILVUS_DIR"
60+
else
61+
echo "ERROR: Failed to create $MILVUS_DIR"
62+
return 1 2>/dev/null || exit 1
63+
fi
64+
fi

0 commit comments

Comments
 (0)