# BeeAI

IBM Research developed BeeAI Framework as a full-featured toolkit for crafting autonomous agents and coordinated multi-agent systems. The framework supports both Python and TypeScript, offering components for reasoning, action execution, and inter-agent collaboration on complex problem-solving tasks.

This guide explains how to route telemetry from BeeAI applications into InteractiveAI using OpenTelemetry-based instrumentation.

### Prerequisites

* InteractiveAI account with API credentials
* LLM provider credentials (OpenAI, Ollama, or other supported provider)

***

### Installation

```bash
pip install beeai-framework interactiveai openinference-instrumentation-beeai beeai-framework[wikipedia]
```

***

### Configuration

Set your API credentials as environment variables:

```python
import os

# InteractiveAI credentials
# Obtain keys from Settings > API Keys in the dashboard
os.environ["INTERACTIVEAI_PUBLIC_KEY"] = "pk-ia-..."
os.environ["INTERACTIVEAI_SECRET_KEY"] = "sk-ia-..."
os.environ["INTERACTIVEAI_HOST"] = "https://app.interactiveai.com"

# LLM provider credentials
# Adjust based on your chosen provider
os.environ["OPENAI_API_KEY"] = "sk-proj-..."
# Ollama runs locally and requires no API key
# Other providers use their respective environment variables
```

Initialize the client and confirm connectivity:

```python
import os
from dotenv import load_dotenv

load_dotenv()

from interactiveai import Interactive

client = Interactive(
    public_key=os.getenv("INTERACTIVEAI_PUBLIC_KEY"),
    secret_key=os.getenv("INTERACTIVEAI_SECRET_KEY"),
    host=os.getenv("HOST"),
)

if client.auth_check():
    print("Connection established")
else:
    print("Authentication failed - verify credentials")
```

***

### Enabling Trace Capture

BeeAI Framework includes a dedicated OpenTelemetry instrumentor. Activate it to capture all framework operations:

```python
from openinference.instrumentation.beeai import BeeAIInstrumentor

BeeAIInstrumentor().instrument()
```

Once enabled, every agent execution, tool invocation, and model call generates spans that flow to InteractiveAI.

***

### Enriching Traces with Context

Layer the InteractiveAI SDK on top of BeeAI instrumentation to attach user identifiers, session data, and custom metadata:

```python
from interactiveai import Interactive
from openinference.instrumentation.beeai import BeeAIInstrumentor
from beeai_framework.agents.react import ReActAgent
from beeai_framework.agents.types import AgentExecutionConfig
from beeai_framework.backend.chat import ChatModel
from beeai_framework.backend.types import ChatModelParameters
from beeai_framework.memory import TokenMemory
from beeai_framework.tools.search.wikipedia import WikipediaTool

client = Interactive()
BeeAIInstrumentor().instrument()

with client.start_as_current_span(name="beeai-research-task") as span:
    
    # Attach context to the trace
    client.update_current_trace(
        user_id="user_789",
        session_id="session_def",
        tags=["beeai", "react-agent", "research"],
        metadata={"use_case": "travel-planning", "environment": "staging"}
    )
    
    llm = ChatModel.from_name(
        "openai:gpt-4o-mini",
        ChatModelParameters(temperature=0.7),
    )
    
    agent = ReActAgent(
        llm=llm,
        tools=[WikipediaTool()],
        memory=TokenMemory(llm)
    )
    
    query = "Summarize the main tourist attractions in Tokyo"
    result = await agent.run(
        prompt=query,
        execution=AgentExecutionConfig(max_iterations=5),
    )
    
    # Capture input and output
    client.update_current_trace(
        input=query,
        output=result.result.text
    )

client.flush()
```

***

### Trace Visibility

The InteractiveAI dashboard displays comprehensive trace data including:

* Agent reasoning steps and iteration counts
* Tool calls with arguments and responses
* Model requests with token usage and latency
* Memory operations and context management
* Complete input/output chains for debugging


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.interactive.ai/integrations/ai-frameworks/beeai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
