Skip to main content

Overview

BeeAI Framework is an open-source, Linux Foundation-hosted framework for building production-grade AI agents with built-in constraint enforcement and rule-based governance. It supports both Python and TypeScript with native watsonx Orchestrate integration. This tutorial shows you how to create and deploy a BeeAI external agent in Python that integrates with watsonx Orchestrate.

Prerequisites

Before starting, ensure you have:

Development & Testing

1

Project setup

Create a project directory and initialize Poetry:
2

Configure dependencies

Install dependencies and update the lock file:
3

Configure your environment variables

Create a .env file in your project root and add your credentials:
.env
Where to find these values:
  • WATSONX_URL: Usually https://us-south.ml.cloud.ibm.com or your region’s URL
  • WATSONX_REGION: Your IBM Cloud region (e.g., us-south, eu-gb, jp-tok)
  • WATSONX_PROJECT_ID: Found in your watsonx.ai project settings
  • WATSONX_API_KEY: Create in IBM Cloud → Manage → Access (IAM) → API keys
  • API_KEY: Generate with openssl rand -base64 32 or use https://randomkeygen.com
  • TAVILY_API_KEY: Get free at https://tavily.com (optional)
4

Create project structure

Create the following directory structure:
5

Create settings module

Create wxo_beeai/settings.py:This file loads environment variables from the .env file, validates required configurations with Pydantic, and provides type-safe access to settings across the app.
wxo_beeai/settings.py
6

Create custom tools

Create wxo_beeai/tools.py:This code defines a web search tool powered by the Tavily API. The @tool decorator registers it with the BeeAI Framework, and it’s configured to perform advanced searches returning up to 10 results.
wxo_beeai/tools.py
7

Create main application

Create wxo_beeai/app.py:The following code launches an HTTP server that exposes a RequirementAgent built for deep research.It connects key components — an unconstrained memory, a Watsonx chat model, reasoning tools (Think + Web Search), and runtime rules that guide the agent’s thinking process.
wxo_beeai/app.py
Key components:
  • Memory — UnconstrainedMemory: Stores the full conversation history
  • LLM — WatsonxChatModel: The Watsonx chat model, configured from AppSettings, with middleware for logging intermediate steps
  • Agent — RequirementAgent: The main reasoning agent with planning capabilities, research-oriented instructions, and tool access
  • Tools — ThinkTool() and search_web_tool: Enable structured reasoning and online information retrieval
  • Requirements — ConditionalRequirement rules:
    • Enforces “thinking” at step 1
    • Prevents consecutive Think tool calls
    • Requires reflection after searches
  • Middleware — GlobalTrajectoryMiddleware: Logs intermediate reasoning and tool usage when enabled in settings
  • Server — WatsonxOrchestrateServer: Registers the agent and serves it via HTTP (0.0.0.0:8080) using the configured API key
  • Error handling — Catches FrameworkError, prints a traceback, and exits cleanly with a clear message
8

Docker configuration

Create Dockerfile:
Dockerfile
Create docker-compose.yml:
docker-compose.yml
9

Test locally

Run your agent locally with Docker Compose:
Or run directly with Poetry:
Tip: Visit http://localhost:8080/docs to see the FastAPI documentation and test the /chat/completions endpoint.Test with curl:

Production Deployment

1

Deploy to IBM Code Engine

Create a Code Engine project

  1. Navigate to IBM Cloud Code Engine Projects
  2. Click Create and name your project (e.g., wxo-beeai)

Create registry secret

  1. Go to Manage → Access (IAM) → API keys
  2. Click Create and save the API key

Create the application

  1. In your Code Engine project, select Applications → Create
  2. Under Code, select Build container image from source code
  3. Configure build details:
    • SSH secret: None
    • Context directory: Your GitHub repository URL
    • Branch: main
    • Dockerfile: Dockerfile
    • Registry secret: Create using your API key
  4. Configure application:
    • Name: beeai-agent
    • Domain mappings: Public
  5. Add environment variables:
    • WATSONX_URL
    • WATSONX_REGION
    • WATSONX_PROJECT_ID
    • WATSONX_API_KEY
    • API_KEY
    • TAVILY_API_KEY (optional)
  6. Click Create
Visit your application URL with /docs appended, e.g. https://beeai-agent.xxxxx.codeengine.appdomain.cloud/docs
2

Register external agent in watsonx Orchestrate

  • In watsonx Orchestrate, click the hamburger menu → Agent Configuration
  • Select Assistants → Add assistant → External Assistant
  • Check External-agent Assistant
  • Configure:
    • Display Name: Research Agent
    • Description: Agent to conduct deep research using web search
    • API Key: Your API_KEY from .env
    • Service Instance URL: https://your-app-url/chat/completions
  • Click Save
3

Use your agent

Use from the GUI, or API
  1. Navigate to Chat in watsonx Orchestrate
  2. Ask research questions that route to your agent:
    • What are the latest developments in quantum computing?
    • Research the current state of renewable energy adoption.
    • What are the recent breakthroughs in AI?
The BeeAI agent will:
  1. Create a research plan
  2. Search the web for relevant information
  3. Reflect on findings after each search
  4. Provide a research-based answer

Next Steps