Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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:8083",
    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._session_service import KAgentSession
import httpx

client = httpx.AsyncClient(base_url="http://localhost:8083")
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:8083", 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_API_URL and KAGENT_GATEWAY_URL to connect to kagent.


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_API_URL - KAgent control-plane API URL
  • KAGENT_GATEWAY_URL - KAgent A2A and MCP gateway URL
  • KAGENT_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.

Metadata

Release files for kagent-openai 1.0.0a8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kagent-openai 1.0.0a8
File Size Uploaded
kagent_openai-1.0.0a8.tar.gz 15.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kagent-openai 1.0.0a8
File Interpreter ABI Platform
kagent_openai-1.0.0a8-py3-none-any.whl Python 3 none any Details

Total release size: 29.3 kB

Release files / kagent_openai-1.0.0a8.tar.gz

Download URL kagent_openai-1.0.0a8.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e4c9f09b2bec58ab33ce774fce2a80b27162ea03f8b12db20ad01632eef4a616
BLAKE2b-256 checksum
How to use checksums
b6f4658d455a8830ed11a37f060e8363c8a272e6516285daec8152b9c677259f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}

Release files / kagent_openai-1.0.0a8-py3-none-any.whl

Download URL kagent_openai-1.0.0a8-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3cd02351a17a97ed927e1ec27a4d33b17e5aafd613a54a1f56838fdf4135da75
BLAKE2b-256 checksum
How to use checksums
6890cf30268c58c207eee1eba28cb1893490707a2d60afd53cffd340aa658b00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}

Release history Release notifications | RSS feed

This release

1.0.0a8 This release

2 release files

0.10.2

2 release files

0.9.12

2 release files

0.9.10

2 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.7

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.19

2 release files

0.7.18

2 release files

0.7.17

2 release files

0.7.16

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page