Skip to content

Latest commit

 

History

History
334 lines (227 loc) · 9.43 KB

File metadata and controls

334 lines (227 loc) · 9.43 KB

CrewAI Logo

WebSearch Agent


What this agent does

Web search agent built with the CrewAI framework. Uses a ReAct-style crew with a web search tool to answer user questions. Use with any OpenAI-compatible API.

Note: CrewAI agents typically need a larger model (e.g. llama3.1:8b) than the other agents in this repo.


Prerequisites

  • uv — Python package manager
  • Podman or Docker — for local container builds (Option A)
  • oc — for OpenShift deployment
  • Helm — for deploying to Kubernetes/OpenShift
  • GNU Make and a bash-compatible shell — on Windows, use WSL (recommended) or Git Bash

Local Development

Initiating base

Here you copy .env.example file into .env

cd agents/crewai/websearch_agent
make init

Edit .env with your configuration, then:

See Local Development for Ollama + Llama Stack setup for local model serving.

Pointing to a remotely hosted model

API_KEY=your-api-key-here
BASE_URL=https://your-model-endpoint.com/v1
MODEL_ID=llama-3.1-8b-instruct

Notes:

  • API_KEY — your API key or contact your cluster administrator
  • BASE_URL — should end with /v1
  • MODEL_ID — model identifier available on your endpoint

Creating environment

Now you will remove old .venv and create new. Next dependencies will be installed.

make env

Setup Ollama

This will install ollama if it is not installed already. Then pull needed models for local work. The default model is llama3.1:8b. To use a different model, pass MODEL=: make ollama MODEL=llama3.2:3b

make ollama

Run llama server

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

make llama-server

Run the interactive web application

Keep this terminal open – the app needs to keep running. You should see output indicating the app started on http://localhost:8000.

cd agents/crewai/websearch_agent
make run-app           # fails if port is already in use and print steps TO-DO

Interactive CLI

For terminal-based testing without a browser:

cd agents/crewai/websearch_agent
make run-cli

Tracing with a local MLflow server

To enable MLflow tracing, add the following to your .env:

MLFLOW_TRACKING_URI = "http://localhost:5000"
MLFLOW_EXPERIMENT_NAME = "crewai-websearch-agent"
MLFLOW_HTTP_REQUEST_TIMEOUT = 2
MLFLOW_HTTP_REQUEST_MAX_RETRIES = 0

Then start the MLflow server in a separate terminal:

# Start the MLflow server
uv run --extra tracing mlflow server --port 5000

When MLFLOW_TRACKING_URI is set, make run-app and make run-cli will automatically install the tracing dependency.

Configuring the LLM provider for tracing

CrewAI can use different LLM providers. Set LLM_PROVIDER to match your provider so MLflow uses the correct autolog integration:

LLM_PROVIDER value MLflow autolog enabled When to use
litellm (default) mlflow.litellm.autolog() OpenAI-compatible endpoints
openai mlflow.openai.autolog() Direct OpenAI API
anthropic mlflow.anthropic.autolog() Anthropic API
gemini mlflow.gemini.autolog() Google Gemini API
azure mlflow.openai.autolog() Azure OpenAI
bedrock mlflow.bedrock.autolog() AWS Bedrock

Tracing with an OpenShift MLflow server

To enable tracing and logging with MLflow on your OpenShift cluster, add the following environment variables to your .env file:

MLFLOW_TRACKING_URI = "https://<openshift-dashboard-url>/mlflow"
MLFLOW_TRACKING_TOKEN = "<your-openshift-token>"
MLFLOW_EXPERIMENT_NAME = "crewai-websearch-agent"
MLFLOW_TRACKING_INSECURE_TLS = "true"
MLFLOW_WORKSPACE = "default"

Notes:

  • MLFLOW_TRACKING_URI - Replace <openshift-dashboard-url> with your OpenShift cluster's data science gateway URL

  • MLFLOW_TRACKING_TOKEN - Your openshift authentication token. It can be obtained from the openshift console.

  • MLFLOW_EXPERIMENT_NAME - A descriptive name for your experiment (e.g., "CrewAI WebSearch Demo")

  • MLFLOW_TRACKING_INSECURE_TLS - Set to "true" if your OpenShift cluster does not use trusted certificates

  • MLFLOW_WORKSPACE - Project name

  • Tracing is optional; if you do not set MLFLOW_TRACKING_URI, the application will run without MLflow logging.

  • If MLFLOW_TRACKING_URI is set, the application will attempt to connect to the MLflow server at startup. If the server is unreachable, the application will log a warning and continue running without tracing.

  • You can control how long the application waits for the MLflow server by setting MLFLOW_HEALTH_CHECK_TIMEOUT (in seconds, default: 5).

Deploying to OpenShift

Setup

cd agents/crewai/websearch_agent
make init

Configuration

Edit .env with your model endpoint and container image:

API_KEY = your-api-key-here
BASE_URL = https://your-model-endpoint.com/v1
MODEL_ID = llama-3.1-8b-instruct
CONTAINER_IMAGE = quay.io/your-username/crewai-websearch-agent:latest

Notes:

  • API_KEY - your API key or contact your cluster administrator

  • BASE_URL - should end with /v1

  • MODEL_ID - model identifier available on your endpoint

  • 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:

    • Quay.io: quay.io/your-username/crewai-websearch-agent:latest
    • Docker Hub: docker.io/your-username/crewai-websearch-agent:latest
    • GHCR: ghcr.io/your-org/crewai-websearch-agent:latest

    Note: OpenShift must be able to pull the container image. Make the image public, or configure an image pull secret for private registries.

Building the Container Image

Login to OC

oc login -u "login" -p "password" https://super-link-to-cluster:111

Login ex. Docker

docker login -u='login' -p='password' quay.io

Option A: Build locally and push to a registry

Requires Podman (or Docker) and a registry account (e.g., Quay.io).

make build    # builds the image locally
make push     # pushes to the registry specified in CONTAINER_IMAGE

Option B: Build in-cluster via OpenShift BuildConfig

No Podman, Docker, or registry account needed — just the oc CLI.

make build-openshift

After the build completes, set CONTAINER_IMAGE in your .env to the internal registry URL printed after the build.

Deploying

Preview manifests (make dry-run)

make dry-run          # preview rendered Helm manifests (secrets redacted)

Deploy (make deploy)

make deploy

Verify deployment

After deploying, the application may take about a minute to become available while the pod starts up.

The route URL is printed after make deploy. You can also retrieve it manually:

oc get route crewai-websearch-agent -o jsonpath='{.spec.host}'

Remove deployment (make undeploy)

make undeploy

See OpenShift Deployment for more details.

Tests

Unit tests

make test

Behavioral tests

Behavioral tests validate tool selection, response quality, latency, and reliability against a live agent. They require MLflow tracing to extract tool_calls from trace spans.

CREWAI_WEBSEARCH_AGENT_URL=https://<agent-route> \
MLFLOW_TRACKING_URI=<mlflow-uri> \
MLFLOW_EXPERIMENT_NAME=<experiment> \
MLFLOW_TRACKING_TOKEN=$(oc whoami -t) \
pytest tests/behavioral/ -v

Skip slow pass@k tests with -m "not slow".

API Endpoints

POST /chat/completions

Non-streaming:

curl -X POST http://localhost:8000/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "What is the best cluster hosting service?"}], "stream": false}'

Streaming:

curl -sN -X POST http://localhost:8000/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "What is the best cluster hosting service?"}], "stream": true}'

Pretty Printed Stream:

curl -sN -X POST http://localhost:8000/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "What is the best cluster hosting service?"}], "stream": true}' |
   jq -R -r -j --stream 'scan("^data:(.*)")[] | fromjson.choices[0].delta.content // empty'

GET /health

curl http://localhost:8000/health

Resources