bee-agent-framework icon indicating copy to clipboard operation
bee-agent-framework copied to clipboard

BeeAI Framework Example

Open jenna-winkler opened this issue 10 months ago • 1 comments

Description

Create an example implementation that demonstrates how to integrate the BeeAI Framework with IBM watsonx Agent Connect, similar to the existing LangGraph and CrewAI examples on the connect.watson-orchestrate.ibm.com/examples page.

The BeeAI Framework example should follow a similar structure as the other examples, showing how to implement the required API endpoints for Agent Connect integration.

Acceptance Criteria

  • Code successfully implements the Agent Connect API with BeeAI Framework
  • All functionality is demonstrated with examples
  • Code is well-structured/follows best practices
  • Documentation clearly explains the integration approach

Reference

  • https://connect.watson-orchestrate.ibm.com/examples

jenna-winkler avatar May 01 '25 19:05 jenna-winkler

Plan is to use RequirementAgent example here cc @Tomas2D

I am on point to share code snippet with @geneknit on Monday when we do the release

jenna-winkler avatar May 15 '25 15:05 jenna-winkler

How can we submit a BeeAI example to their documentation? @jenna-winkler

xjacka avatar Jul 24 '25 13:07 xjacka

@geneknit can you please connect us with the right person?

jenna-winkler avatar Jul 24 '25 13:07 jenna-winkler

I will pass the example, feel free to comment.

from collections.abc import Callable
from typing import Any

from fastapi import Header

import beeai_framework.adapters.watsonx_orchestrate._api as watsonx_orchestrate_api
from beeai_framework.adapters.watsonx_orchestrate.serve.agent import (
    WatsonxOrchestrateServerAgent,
)
from beeai_framework.adapters.watsonx_orchestrate.serve.api import WatsonxOrchestrateAPI
from beeai_framework.adapters.watsonx_orchestrate.serve.server import (
    WatsonxOrchestrateServer,
    WatsonxOrchestrateServerConfig,
)
from beeai_framework.agents.experimental import RequirementAgent
from beeai_framework.backend import ChatModel
from beeai_framework.tools.think import ThinkTool


class AgentConnectFrameworkAPI(WatsonxOrchestrateAPI):
    def __init__(
        self,
        *,
        create_agent: Callable[[], WatsonxOrchestrateServerAgent],
        api_key: str | None = None,
        fast_api_kwargs: dict[str, Any] | None = None,
    ) -> None:
        super().__init__(
            create_agent=create_agent,
            api_key=api_key,
            fast_api_kwargs=fast_api_kwargs,
            stateful=True,
        )
        # add Agent Connect Framework specific routes
        self._router.add_api_route(
            "/v1/chat",
            self.handler,
            methods=["POST"],
            response_model=watsonx_orchestrate_api.ChatCompletionResponse,
        )
        self._router.add_api_route(
            "/v1/agents",
            self.discover_agents,
            methods=["GET"],
            response_model=dict[str, Any],
        )
    
    # Custom handler for chat completions to suppurt custom thread_id header
    async def handler(
        self,
        request: watsonx_orchestrate_api.ChatCompletionRequestBody,
        thread_id: str = Header(None, alias="X-THREAD-ID"),
        api_key: str | None = Header(None, alias="X-API-Key"),
    ) -> Any:
        return await super().handler(request, thread_id, api_key=api_key)

    def discover_agents(self) -> dict[str, Any]:
        """
        Returns a dictionary describing available agents and their capabilities.
        """
        return {
            "agents": [
                {
                    "name": "BeeAI framework Example Agent",
                    "description": "A simple BeeAI agent that demonstrates Agent Connect integration",
                    "provider": {
                        "organization": "Your Organization",
                        "url": "https://your-organization.com",
                    },
                    "version": "1.0.0",
                    "documentation_url": "https://framework.beeai.dev",
                    "capabilities": {"streaming": True},
                }
            ]
        }


agent = RequirementAgent(llm=ChatModel.from_name("ollama:llama3.1"), tools=[ThinkTool()])
# Create the server with the custom API and configuration
server = WatsonxOrchestrateServer(
    api_cls=AgentConnectFrameworkAPI,
    config=WatsonxOrchestrateServerConfig(port=8000),
)
# Register the agent with the server
server.register(agent)
# Start the server
server.serve()

xjacka avatar Jul 25 '25 11:07 xjacka

This has been passed on to the team and is being added: IBM Agent Connect - BeeAI Framework Example

Will close once we see its added

jenna-winkler avatar Jul 30 '25 14:07 jenna-winkler

Update from the team

Hi all, FYI, we want to update the docs by Aug 14th—date due to other deliverables, lots of parallel work, appreciate the understanding

jenna-winkler avatar Aug 04 '25 14:08 jenna-winkler

The BeeAI Framework example is published. closing....

xjacka avatar Aug 19 '25 07:08 xjacka