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:- Python 3.11 or higher
- Poetry (Python package manager)
- BeeAI Framework along with the watsonx Orchestrate extension installed (
pip install 'beeai-framework[watsonx-orchestrate]') - Docker
- An active watsonx Orchestrate account
- Tavily API key (optional, for web search) - Get a free API key at tavily.com
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 Where to find these values:
.env file in your project root and add your credentials:.env
- 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 32or 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 Key components:
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
- Memory —
UnconstrainedMemory: Stores the full conversation history - LLM —
WatsonxChatModel: The Watsonx chat model, configured fromAppSettings, with middleware for logging intermediate steps - Agent —
RequirementAgent: The main reasoning agent with planning capabilities, research-oriented instructions, and tool access - Tools —
ThinkTool()andsearch_web_tool: Enable structured reasoning and online information retrieval - Requirements —
ConditionalRequirementrules:- 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 Create
Dockerfile:Dockerfile
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
- Navigate to IBM Cloud Code Engine Projects
- Click Create and name your project (e.g., wxo-beeai)
Create registry secret
- Go to Manage → Access (IAM) → API keys
- Click Create and save the API key
Create the application
- In your Code Engine project, select Applications → Create
- Under Code, select Build container image from source code
- Configure build details:
- SSH secret: None
- Context directory: Your GitHub repository URL
- Branch: main
- Dockerfile: Dockerfile
- Registry secret: Create using your API key
- Configure application:
- Name: beeai-agent
- Domain mappings: Public
- Add environment variables:
WATSONX_URLWATSONX_REGIONWATSONX_PROJECT_IDWATSONX_API_KEYAPI_KEYTAVILY_API_KEY(optional)
- Click Create
/docs appended, e.g. https://beeai-agent.xxxxx.codeengine.appdomain.cloud/docs2
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
- Navigate to Chat in watsonx Orchestrate
- 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?
- Create a research plan
- Search the web for relevant information
- Reflect on findings after each search
- Provide a research-based answer
Next Steps
- Explore BeeAI Framework documentation
- Learn about RequirementAgent capabilities
- Add custom tools for your specific use case
- Experiment with different agent requirements and constraints

