Skip to main content

KAgent OpenAI Agents SDK Integration

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


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

Optional tools

BYO harnesses keep agent behavior in user code. Import the basic filesystem and bash tools you need from kagent.openai.tools:

from agents.agent import Agent
from kagent.openai.tools import bash, edit_file, read_file, write_file

agent = Agent(
    name="Assistant",
    instructions="Use tools when appropriate.",
    tools=[read_file, write_file, edit_file, bash],
)

Skill discovery and loading are user-implemented in BYO harnesses.

File and bash tools share /data/workspace within an Actor. Substrate snapshots preserve that directory; applications create any upload or output directories when needed. See runtime helpers.


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"]

Load /config/config.json with KAgentConfig.from_file() 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


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.

Runtime configuration file

Managed entry points call materialize_from_bootstrap("/config") from kagent.core to fetch and materialize the controller bundle before KAgentConfig.from_file(). The file loader does not bootstrap. For a standalone process, create the file and load it directly:

{"runtime":{"control_plane_url":"http://localhost:8083","gateway_url":"http://localhost:8083","name":"my-agent","namespace":"default","log_level":"info"}}

Provider credentials and standard OTEL_* overrides remain environment inputs.

Metadata

Release files for kagent-openai 1.0.0

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.0
File Size Uploaded Provenance Actions
kagent_openai-1.0.0.tar.gz 14.9 kB Without provenance Details for kagent_openai-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 27.9 kB

Release files / kagent_openai-1.0.0.tar.gz

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

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

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

Security for kagent-openai 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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