Skip to content

Commit 9848732

Browse files
committed
update the init file to load variables form .env then check if they are populated.
change README.md file change the run server path add template.env
1 parent 773ba1b commit 9848732

8 files changed

Lines changed: 175 additions & 64 deletions

File tree

Lines changed: 48 additions & 16 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+
```
1929

2030
Copy .env file
31+
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
Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,64 @@
11
#!/bin/bash
2-
# Usage:
3-
# ./init.sh
2+
#
3+
# init.sh - Environment bootstrap for the LangGraph ReAct Agent
4+
#
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.
49

5-
set -e
10+
#
11+
# Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
12+
#
613

7-
source .env && echo "Environment variables loading from .env file"
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"
819

9-
if [ -z "$API_KEY" ]; then
10-
echo "API_KEY not set, check .env file"
11-
exit 1
12-
fi
20+
# 1. Load .env, export variables, and collect their names for validation
21+
ENV_VARS=()
1322

14-
if [ -z "$BASE_URL" ]; then
15-
echo "BASE_URL not set, check .env file"
16-
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
1735
fi
1836

19-
if [ -z "$MODEL_ID" ]; then
20-
echo "MODEL_ID not set, check .env file"
21-
exit 1
22-
fi
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
2351

24-
if [ -z "$CONTAINER_IMAGE" ]; then
25-
echo "CONTAINER_IMAGE not set, check .env file"
26-
exit 1
27-
fi
52+
# 3. Ensure milvus_data directory exists at repo root
53+
MILVUS_DIR="$REPO_ROOT/milvus_data"
54+
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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# API_KEY=
2+
# BASE_URL=
3+
# MODEL_ID=
4+
# CONTAINER_IMAGE=

0 commit comments

Comments
 (0)