Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 113 additions & 53 deletions agents/base/openai_responses_agent/README.md
Original file line number Diff line number Diff line change
@@ -1,110 +1,165 @@
<div style="text-align: center;">

# OpenAI Responses Agent

Agent **without any agentic framework**: uses only the **OpenAI Python client** and **pure Python** (Responses API). No LlamaStack, LangChain, LlamaIndex, etc. – to show it can be done without frameworks. Uses `AIAgent` with chat, tools, and Action/Observation loop. Compatible with OpenAI API or any OpenAI-compatible endpoint (e.g. `BASE_URL` override). Python 3.12+.
</div>

# Use Agent Locally
Agent **without any agentic framework**: uses only the **OpenAI Python client** and **pure Python** (Responses API). No LlamaStack, LangChain, LlamaIndex, etc. Uses `AIAgent` with chat, tools, and Action/Observation loop. Compatible with OpenAI API or any OpenAI-compatible endpoint (e.g. `BASE_URL` override). Python 3.12+.

### Installation
---

```bash
git clone <repository-url>
cd Agentic-Starter-Kits
```
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
### Preconditions

If you want to install Ollama: [Ollama site](https://ollama.com/) or [Brew](https://formulae.brew.sh/formula/ollama#default).
- Copy/paste the `.env` file and set values for your environment
- Choose **local** or **RH OpenShift Cluster** and fill the needed values
- Run `./init.sh` to load values from `.env` into the environment

**Install agent dependencies** (OpenAI client):
Copy `.env` file:

```bash
cd agents/base/openai_responses_agent
uv pip install -e .
# or: poetry install
cp template.env agents/base/openai_responses_agent/.env
```

### Setup Instructions
#### Local

Edit the `.env` file with your local configuration:

```
BASE_URL=http://localhost:8321
MODEL_ID=ollama/llama3.2:3b
API_KEY=not-needed
CONTAINER_IMAGE=not-needed
```

**Option A – OpenAI API**
> **Local setup (Ollama):** Port and model name can differ depending on your setup (e.g. Llama Stack on port 8321 vs Ollama on 11434, or a different model ID). Check your running services and `run_llama_server.yaml` (if using Llama Stack) and set `BASE_URL` and `MODEL_ID` accordingly.

Create `.env` in the agent directory (or use repo `template.env`):
Or for **OpenAI API** directly:

```env
```
BASE_URL=https://api.openai.com/v1
MODEL_ID=gpt-4o-mini
API_KEY=sk-...
CONTAINER_IMAGE=not-needed
```

**Option B – Local OpenAI-compatible endpoint (e.g. Ollama)**
#### OpenShift Cluster

1. Pull model and run Ollama (or another OpenAI-compatible server).
2. In `.env` set e.g. `BASE_URL=http://localhost:11434/v1`, `MODEL_ID=llama3.2`, `API_KEY=not-needed` (if not required).
Edit the `.env` file and fill in all required values:

**Configure Environment Variables**
```
API_KEY=your-api-key-here
BASE_URL=https://your-llama-stack-distribution.com/v1
MODEL_ID=llama-3.1-8b-instruct
CONTAINER_IMAGE=quay.io/your-username/openai-responses-agent:latest
```

**Notes:**

- `API_KEY` – contact your cluster administrator
- `BASE_URL` – should end with `/v1`
- `MODEL_ID` – contact your cluster administrator
- `CONTAINER_IMAGE` – full image path where the agent container will be pushed and pulled from. The image is built locally, pushed to this registry, and then deployed to OpenShift.

Format: `<registry>/<namespace>/<image-name>:<tag>`

Examples:

Copy the template (from repo root: `template.env`) or create `.env` in the agent directory:
- Quay.io: `quay.io/your-username/openai-responses-agent:latest`
- Docker Hub: `docker.io/your-username/openai-responses-agent:latest`
- GHCR: `ghcr.io/your-org/openai-responses-agent:latest`

Go to agent dir:

```bash
cp ../../../template.env .env
cd agents/base/openai_responses_agent
```

Edit `.env` with `BASE_URL`, `MODEL_ID`, and `API_KEY` as above.
Make scripts executable:

```bash
chmod +x init.sh
```

**Run the example**
Load values from `.env` into environment variables:

```bash
cd examples
python execute_ai_service_locally.py
./init.sh
```

**⚡ Or with [uv](https://docs.astral.sh/uv/)** (from repo root):
---

## Local usage (Ollama + LlamaStack Server)

Create package with agent and install it in venv:

1. Create venv and activate:
```bash
uv venv --python 3.12
source .venv/bin/activate
uv pip install -e .
uv pip install ollama
```

2. Copy shared utils into the agent package:
Install Ollama from the [Ollama site](https://ollama.com/) or via Brew:

```bash
cp utils.py agents/base/openai_responses_agent/src/openai_responses_agent_base/
# brew install ollama
# or
curl -fsSL https://ollama.com/install.sh | sh
```

3. Install agent (editable) and its requirements:
Pull required models:

```bash
uv pip install -e agents/base/openai_responses_agent/. -r agents/base/openai_responses_agent/requirements.txt
ollama pull llama3.2:3b
ollama pull embeddinggemma:latest
```

4. Run the example:
Start Ollama service:

```bash
uv run agents/base/openai_responses_agent/examples/execute_ai_service_locally.py
ollama serve
```

# Deployment on Red Hat OpenShift Cluster
> **Keep this terminal open!**
> Ollama needs to keep running.

### Step 1: Initialize the Agent
Start LlamaStack server:

```bash
cd agents/base/openai_responses_agent
chmod +x init.sh deploy.sh
./init.sh
llama stack run ../../../run_llama_server.yaml
```

> **Keep this terminal open** – the server needs to keep running.
> You should see output indicating the server started on `http://localhost:8321`.

Run the example:

```bash
uv run agents/base/openai_responses_agent/examples/execute_ai_service_locally.py
```

This loads `.env`, validates variables, and copies `utils.py` into the agent package.
---

## Deployment on Red Hat OpenShift Cluster

### Step 2: Build Image and Deploy
Make deploy script executable:

```bash
chmod +x deploy.sh
```

Build image and deploy agent:

```bash
./deploy.sh
```

This creates the API key secret, builds and pushes the image, and deploys the agent (Deployment, Service, Route).
This will:

### Step 3: Test the Agent
- Create Kubernetes secret for API key
- Build and push the Docker image
- Deploy the agent to OpenShift
- Create Service and Route

Get the route host:
Get the route URL:

```bash
oc get route openai-responses-agent -o jsonpath='{.spec.host}'
Expand All @@ -115,9 +170,14 @@ Send a test request:
```bash
curl -X POST https://<YOUR_ROUTE_URL>/chat \
-H "Content-Type: application/json" \
-d '{"message": "How much does a Lenovo Laptop costs and what are the reviews?"}'
-d '{"message": "How much does a Lenovo Laptop cost and what are the reviews?"}'
```

## References
---

## Agent-Specific Documentation

- [OpenAI Python client](https://github.com/openai/openai-python) and [Responses API](https://platform.openai.com/docs/api-reference/responses/create)
- [OpenAI Python client](https://github.com/openai/openai-python)
- [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses/create)
- [Ollama](https://ollama.com/)
- [Ollama (Homebrew)](https://formulae.brew.sh/formula/ollama#default)
4 changes: 4 additions & 0 deletions agents/base/openai_responses_agent/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ packages = [
python = ">=3.12"
python-dotenv = "^1.0.0"
openai = ">=1.0.0"
llama-stack = ">=0.5.0"
setuptools = "69.5.1"
milvus-lite = "2.5.1"
pymilvus = "2.6.9"

[tool.poetry.group.dev]
optional = true
Expand Down
2 changes: 1 addition & 1 deletion run_llama_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ providers:
- provider_id: milvus
provider_type: inline::milvus
config:
db_path: ${MILVUS_DB_PATH:-./milvus_data/milvus_lite.db}
db_path: ./milvus_data/milvus_lite.db
persistence:
namespace: vector_io::milvus
backend: kv_default
Expand Down