> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agnost.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CAMEL-AI

> Capture CAMEL-AI ChatAgent turns, model calls, and tool calls with OpenInference

## Choose a setup method

| Method | Use it when |
| - | - |
| **Agnost AI skill** | You want your coding agent to inspect the app, make the change, and verify it. |
| **Agnost AI SDK** | You want explicit control over the interaction boundaries and fields. |
| **OpenTelemetry** | The framework already emits useful spans or you operate an OTel pipeline. |

Start with one method for a call path. Combining SDK tracking with framework
OpenTelemetry on the same call can create duplicate interactions.

## Recommended: Agnost AI skill

> [!NOTE]
>
> **Recommended.** Choose this path when you want your coding agent to inspect the
> project, select a supported transport, make the smallest instrumentation change,
> send a test event, and verify that it reached Agnost AI.

Install the skill once in your coding-agent environment:

```bash theme={null}
npx skills add AgnostAI/skills --skill agnost-ai
```

Run the framework-specific prompt below from the application root. Review the
resulting diff before deploying it.

```text theme={null}
Use the agnost-ai skill to add Agnost AI analytics to this CAMEL-AI application.
Org ID: your-org-id
Instrument the real ChatAgent.step() path and verify one fresh interaction.
```

## Manual setup: Agnost AI SDK

```bash theme={null}
pip install agnost
```

```python theme={null}
import agnost

agnost.init("your-org-id")
interaction = agnost.begin(
    user_id="u-42",
    agent_name="camel-support",
    input=prompt,
    conversation_id="sess-123",  # groups turns into one conversation
)
if interaction is None:
    raise RuntimeError("Agnost is not initialized. Call agnost.init() first.")
try:
    response = agent.step(prompt)
    interaction.end(output=response.msgs[0].content)
except Exception as exc:
    interaction.end(output=str(exc), success=False)
    raise
```

Call `agnost.shutdown()` once when the application exits, not after each request.
Shutting down per request disables telemetry for later agent runs in the same process.

## Manual setup: OpenTelemetry

CAMEL-AI has no OpenTelemetry export of its own. Its built-in tracing hooks target AgentOps, Langfuse, and TraceRoot. CAMEL calls each model provider through that provider's Python SDK, so instrument the SDK instead. This guide uses Claude through the [OpenInference Anthropic instrumentation](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-anthropic). For OpenAI models, swap in `openinference-instrumentation-openai` and `OpenAIInstrumentor`. Add an OpenInference decorator to each tool function, and wrap each turn in one span that carries the user's message and the agent's answer.

### 1. Install

```bash theme={null}
pip install camel-ai "anthropic>=1.8,<2" "mcp<2" openinference-instrumentation-anthropic \
            opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
```

Tested with `camel-ai` 0.2.90, `anthropic` 1.17.0, `mcp` 1.30.0, `openinference-instrumentation-anthropic` 3.3.9, and `opentelemetry-sdk` 1.45.2 on Python 3.12.

The two pins keep `camel-ai` 0.2.90 importable and runnable. With `mcp` 2.x, `import camel.agents` fails on `from mcp.server import FastMCP`. With `anthropic` 2.x, CAMEL's Anthropic token counter fails with `TypeError: Cannot instantiate typing.Union`. The instrumentation needs `anthropic` 1.8 or newer.

### 2. Point OpenTelemetry at Agnost AI and run an agent

```python theme={null}
import os

# Recent anthropic SDKs emit their own span per API call. Turn it off so each
# model call shows up once, from the OpenInference instrumentation.
os.environ["ANTHROPIC_OPEN_TELEMETRY"] = "false"

from camel.agents import ChatAgent
from camel.models import ModelFactory
from camel.toolkits import FunctionTool
from camel.types import ModelPlatformType, ModelType
from openinference.instrumentation import TracerProvider, using_attributes
from openinference.instrumentation.anthropic import AnthropicInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import BatchSpanProcessor

provider = TracerProvider(resource=Resource.create({"service.name": "my-camel-agent"}))
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(
    endpoint="https://otel.agnost.ai/v1/traces",
    headers={"X-Agnost-Org-ID": os.environ["AGNOST_ORG_ID"]},
)))
AnthropicInstrumentor().instrument(tracer_provider=provider)
tracer = provider.get_tracer("agnost")


@tracer.tool
def get_order_status(order_id: str) -> str:
    r"""Look up the shipping status of an order.

    Args:
        order_id (str): The order ID.
    """
    return "shipped"


model = ModelFactory.create(
    model_platform=ModelPlatformType.ANTHROPIC,
    model_type=ModelType.CLAUDE_HAIKU_4_5,
    model_config_dict={"max_tokens": 1024},
)
agent = ChatAgent(
    system_message="You are a support agent for an online store. Keep answers short.",
    model=model,
    tools=[FunctionTool(get_order_status)],
)


def run_turn(message: str, user_id: str, session_id: str) -> str:
    """Run one agent turn and record it as one Agnost AI conversation turn."""
    with using_attributes(user_id=user_id, session_id=session_id):
        with tracer.start_as_current_span("agent_turn", openinference_span_kind="agent") as span:
            span.set_input(message)
            response = agent.step(message)
            answer = response.msgs[0].content
            span.set_output(answer)
            return answer


print(run_turn("Where is my order A-1042?", user_id="user-42", session_id="session-abc"))
provider.shutdown()  # flush spans before a short script exits
```

What each piece does:

* **`TracerProvider` from `openinference.instrumentation`** is the OpenTelemetry SDK provider with OpenInference helpers added. Its tracers give you `@tracer.tool` and `openinference_span_kind`.
* **`AnthropicInstrumentor().instrument()`** traces every `messages.create` call CAMEL makes, with input and output messages, tool calls, and token counts.
* **`@tracer.tool`** records each tool call with its arguments and result. It keeps the function's name, signature, and docstring, so `FunctionTool` builds the same tool schema.
* **`using_attributes(user_id=..., session_id=...)`** writes `user.id` and `session.id` onto every OpenInference span inside the block. Every turn with the same `session_id` lands in the same Agnost AI conversation.
* **The `agent_turn` span** becomes the root of each trace. Agnost AI builds the conversation transcript from each trace's root span, so the wrapper holds the plain user message and the final answer.
* **`model_config_dict={"max_tokens": 1024}`** is required for Anthropic models in CAMEL. Without it, CAMEL sends `max_tokens: null` and Anthropic rejects the request.

In a long-running server, create the `TracerProvider` and call `instrument()` once at startup, call `run_turn` per request, and call `provider.shutdown()` on graceful shutdown.

### What appears in Agnost AI

* **Conversations**: one per `session_id`. Agnost AI keeps the raw session ID as `original_conversation_id` in the conversation metadata.
* **Users**: the `user_id` you pass to `using_attributes`.
* **Messages**: the user's message and the agent's answer for each turn, from the `agent_turn` span.
* **Events**: the turn (`agent`), each `messages.create` call (`llm`) with the model name, messages, and token counts, and each tool call (`tool`) with arguments and result. CAMEL counts context tokens through Anthropic's token counting API, so each step also shows a `messages.count_tokens` event.

### Verify

Run the script, wait up to a minute for ingestion, then open **Conversations** in Agnost AI. Confirm the conversation shows your `user_id`, a user message and an assistant answer, two `messages.create` events, and a `get_order_status` tool event with arguments and a result.

### Troubleshooting

* **Nothing arrives**: confirm the exporter's headers contain `X-Agnost-Org-ID`, and that the script calls `provider.shutdown()` or `provider.force_flush()` before it exits. `BatchSpanProcessor` exports in the background.
* **The log says `AnthropicInstrumentor only instruments "anthropic >= 1.8.0"`**: an older `anthropic` is installed, so no model spans are created. Install `"anthropic>=1.8,<2"`.
* **`ImportError: cannot import name 'FastMCP' from 'mcp.server'`**: install `"mcp<2"`.
* **`TypeError: Cannot instantiate typing.Union` on the first step**: `anthropic` 2.x is installed. Install `"anthropic>=1.8,<2"`.
* **No tool events**: decorate each tool function with `@tracer.tool` before passing it to `FunctionTool`.
* **User or conversation is missing**: call `agent.step()` inside the `using_attributes` block.
* **Each model call appears twice**: set `ANTHROPIC_OPEN_TELEMETRY=false` before CAMEL creates the model.

### References

* [OpenInference Anthropic instrumentation](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-anthropic)
* [OpenInference tracing helpers](https://github.com/Arize-ai/openinference/tree/main/python/openinference-instrumentation)
* [CAMEL-AI models](https://docs.camel-ai.org/key_modules/models)
* [CAMEL-AI agent tracking with AgentOps](https://docs.camel-ai.org/cookbooks/advanced_features/agents_tracking)

## Next steps

* [Conversations](https://docs.agnost.ai/using-conversations.md): review the complete CAMEL-AI session.
* [Events](https://docs.agnost.ai/using-events.md): inspect model and tool activity.
* [Patterns](https://docs.agnost.ai/using-patterns.md): organize production conversations by what users wanted.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.