Skip to main content

OpenInference BeeAI Instrumentation

Project description

OpenInference Instrumentation for BeeAI

This module provides automatic instrumentation for BeeAI framework. It integrates seamlessly with the @opentelemetry/sdk-trace-node to collect and export telemetry data.

Installation

pip install openinference-instrumentation-beeai

Quickstart

This quickstart shows you how to instrument your guardrailed LLM application

Install required packages.

pip install beeai-framework arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp

Start Phoenix in the background as a collector. By default, it listens on http://localhost:6006. You can visit the app via a browser at the same address. (Phoenix does not send data over the internet. It only operates locally on your machine.)

python -m phoenix.server.main serve

Set up BeeAIInstrumentor to trace your crew and send the traces to Phoenix at the endpoint defined below. The openinference_setup.py file.

import logging

from opentelemetry import trace as trace_api
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

from openinference.instrumentation.beeai import BeeAIInstrumentor

logging.basicConfig(level=logging.DEBUG)


def setup_observability(endpoint: str = "http://localhost:6006/v1/traces") -> None:
    """
    Sets up OpenTelemetry with OTLP HTTP exporter and instruments the beeai framework.
    """
    resource = Resource(attributes={})
    tracer_provider = trace_sdk.TracerProvider(resource=resource)
    tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
    tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
    trace_api.set_tracer_provider(tracer_provider)

    BeeAIInstrumentor().instrument()

Set up a simple ReActAgent to get the current weather in Las Vegas.

import asyncio
import sys
import traceback

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.errors import FrameworkError
from beeai_framework.memory import TokenMemory
from beeai_framework.tools.search import DuckDuckGoSearchTool, WikipediaTool
from beeai_framework.tools.tool import AnyTool
from beeai_framework.tools.weather.openmeteo import OpenMeteoTool
from openinference_setup import setup_observability

setup_observability()

llm = ChatModel.from_name(
    "ollama:granite3.1-dense:8b",
    ChatModelParameters(temperature=0),
)

tools: list[AnyTool] = [
    WikipediaTool(),
    OpenMeteoTool(),
    DuckDuckGoSearchTool(),
]

agent = ReActAgent(llm=llm, tools=tools, memory=TokenMemory(llm))

prompt = "What's the current weather in Las Vegas?"


async def main() -> None:
    response = await agent.run(
        prompt=prompt,
        execution=AgentExecutionConfig(
            max_retries_per_step=3, total_max_retries=10, max_iterations=20
        ),
    )

    print("Agent 🤖 : ", response.result.text)


if __name__ == "__main__":
    try:
        asyncio.run(main())
    except FrameworkError as e:
        traceback.print_exc()
        sys.exit(e.explain())

More Info

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openinference_instrumentation_beeai-0.1.12.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file openinference_instrumentation_beeai-0.1.12.tar.gz.

File metadata

File hashes

Hashes for openinference_instrumentation_beeai-0.1.12.tar.gz
Algorithm Hash digest
SHA256 97a24e68be07baa5d3c0b31f16e5ca61c31aec98c5f1999d091a47ed76be66f8
MD5 1cc0d303bfd90cf1f95f2c8a328cb24c
BLAKE2b-256 c912655ee0ef15e921cd98a301029ff1fd502b4769cec9814955b9f76196b6c3

See more details on using hashes here.

File details

Details for the file openinference_instrumentation_beeai-0.1.12-py3-none-any.whl.

File metadata

File hashes

Hashes for openinference_instrumentation_beeai-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 c23a4c19b4c571371ed6a2ebbea8a50ecd904fa483fa8ca17dadcac1ba0ae8d6
MD5 54f4537027b57832a7b9b5570f502865
BLAKE2b-256 3c636da7a0763a3d5d6829a7428c1a9b99a87244c02da0e6eca401e581fd4d2d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page