Skip to main content

OpenAI integration for KAgent with A2A server support

Project description

KAgent OpenAI Agents SDK Integration

OpenAI Agents SDK integration for KAgent with A2A (Agent-to-Agent) protocol support, session management, and optional skills integration.


Quick Start

from kagent.openai import KAgentApp
from agents.agent import Agent

# Create your OpenAI agent
agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    tools=[my_tool],  # Optional
)

# Create KAgent app
app = KAgentApp(
    agent=agent,
    agent_card={
        "name": "my-openai-agent",
        "description": "My OpenAI agent",
        "version": "0.1.0",
        "capabilities": {"streaming": True},
        "defaultInputModes": ["text"],
        "defaultOutputModes": ["text"]
    },
    kagent_url="http://localhost:8080",
    app_name="my-agent"
)

# Run
fastapi_app = app.build()
# uvicorn run_me:fastapi_app

Agent with Skills

Skills provide domain expertise through filesystem-based instruction files and helper tools (read/write/edit files, bash execution). We provide a function to load all skill-related tools. Otherwise, you can select the ones you need by importing from kagent.openai.tools.

from agents.agent import Agent
from kagent.openai import get_skill_tools

tools = [my_custom_tool]
tools.extend(get_skill_tools("./skills"))

agent = Agent(
    name="SkillfulAgent",
    instructions="Use skills and tools when appropriate.",
    tools=tools,
)

See skills README for skill format and structure.


Session Management

Sessions persist conversation history in KAgent backend:

from agents.agent import Agent
from agents.run import Runner
from kagent.openai.agent._session_service import KAgentSession
import httpx

client = httpx.AsyncClient(base_url="http://localhost:8080")
session = KAgentSession(
    session_id="conversation_123",
    client=client,
    app_name="my-agent",
)

agent = Agent(name="Assistant", instructions="Be helpful")
result = await Runner.run(agent, "Hello!", session=session)

Local Development

Test without KAgent backend using in-memory mode:

app = KAgentApp(
    agent=agent,
    agent_card=agent_card,
    kagent_url="http://localhost:8080",
    app_name="test-agent"
)

fastapi_app = app.build_local()  # In-memory, no persistence

Deployment

Standard Docker deployment:

FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY agent.py .
CMD ["uvicorn", "agent:fastapi_app", "--host", "0.0.0.0", "--port", "8000"]

Set KAGENT_URL environment variable to connect to KAgent backend.


Architecture

Component Purpose
KAgentApp FastAPI application builder with A2A support
KAgentSession Session persistence via KAgent REST API
OpenAIAgentExecutor Executes agents with event streaming

Environment Variables

  • KAGENT_URL - KAgent backend URL (default: http://localhost:8080)
  • LOG_LEVEL - Logging level (default: INFO)

Examples

See samples/openai/ for complete examples:

  • basic_agent/ - Simple agent with custom tools
  • More examples coming soon

See Also


License

See repository LICENSE file.

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

kagent_openai-0.9.0b7.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

kagent_openai-0.9.0b7-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file kagent_openai-0.9.0b7.tar.gz.

File metadata

  • Download URL: kagent_openai-0.9.0b7.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kagent_openai-0.9.0b7.tar.gz
Algorithm Hash digest
SHA256 cac5bc00a0dcccbc1573d7bbec3c0ce0aed70f28f0b517886926b4f14fb2b1ee
MD5 b3fe67b8246f93cc718e31b715d04db1
BLAKE2b-256 f0667be2357e269a5e76d5e3caba075bd3d2b24d51564369e53a7d087b3818fc

See more details on using hashes here.

File details

Details for the file kagent_openai-0.9.0b7-py3-none-any.whl.

File metadata

  • Download URL: kagent_openai-0.9.0b7-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kagent_openai-0.9.0b7-py3-none-any.whl
Algorithm Hash digest
SHA256 38a2adb4ae59c38e9141eb4855ad464f376e1f2413f82eea6feef9774075bff2
MD5 451ec470ef6672a3986634bde318819e
BLAKE2b-256 419f40e6e95bdef07dda419eac40efbbddd10b2a002829fd47dfd16dee96cce7

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