DocsHarness SDK

BEEOS CLOUD / DEVELOPER REFERENCE

Python agent runtime

The stdlib-only BeeOSAgentRuntime facade of the Python package root.

The Python package root exposes BeeOSAgentRuntime, a small facade that dispatches chat messages, cancellations and runtime methods to your handlers and offers lease-token-authenticated helpers. It uses only the standard library. This module has no TypeScript counterpart.

BeeOSAgentRuntime

Python beeos_cloud_harness_sdk · Python only

Facade for a custom agent harness in Python. It sends authenticated requests to Agent Gateway and the message service, groups the calls into namespaces (agent, messages, chat, files, canvas, a2a, messaging), and routes inbound chat prompts, cancellations and runtime methods to the handlers you register.

class BeeOSAgentRuntime
def __init__(agent_gateway_url: str, message_service_url: str, instance_id: str, agent_id: str, token: str | Callable[[], str], framework: str = 'custom', transport=None)

Python · Constructor

ParameterTypeRequiredDefaultDescription
agent_gateway_urlstryesBase URL of Agent Gateway.
message_service_urlstryesBase URL of the message service.
instance_idstryesIdentifier of the instance; sent as X-BeeOS-Instance-ID.
agent_idstryesIdentifier of the agent; sent as X-BeeOS-Agent-ID.
tokenstr | Callable[[], str]yesCredential sent in the Authorization header, either a string or a function that returns the current one. A value that already contains a space is sent as it is; otherwise Bearer is added.
frameworkstrno'custom'Name of the agent framework that is being connected. Defaults to custom.
transportnoNoneOptional function (method, url, headers, body) -> (status, raw_body, response) that sends the request instead of urllib; useful in tests.

token

Returns the current credential: calls the function when token is a function.

def token() -> str

Python · Parameters

No parameters.

Returns str

register

Registers the handlers for inbound events. Each call replaces all three handlers.

def register(*, on_chat_message=None, on_chat_cancel=None, on_runtime_method=None)

Python · Parameters

ParameterTypeRequiredDefaultDescription
on_chat_messagenoNoneCalled with a chat event dict when a prompt arrives.
on_chat_cancelnoNoneCalled with a cancel event dict (conversationId, targetMessageId, agentId) when a prompt is cancelled.
on_runtime_methodnoNoneCalled with (method, params) for every runtime method. When it is not set, session/prompt goes to on_chat_message and other methods fail with status 501.

Returns void

request

Sends one authenticated JSON request and returns the decoded JSON, or None for an empty or 204 answer. Raises BeeOSAgentError for an error status or when the runtime is closed.

def request(base: str, method: str, path: str, json_body=None, headers=None)

Python · Parameters

ParameterTypeRequiredDefaultDescription
basestryesWhich service to call: gateway for Agent Gateway, anything else for the message service.
methodstryesHTTP method.
pathstryesRequest path.
json_bodynoNoneJSON-compatible request body, or None for no body.
headersnoNoneAdditional request headers.

Returns void

dispatch_chat_message

Passes a chat event to the on_chat_message handler and returns its result; does nothing when no handler is set.

def dispatch_chat_message(event: dict)

Python · Parameters

ParameterTypeRequiredDefaultDescription
eventdictyesChat event with conversationId, messageId, agentId, text, channelId, sessionKey and files.

Returns void

dispatch_chat_cancel

Passes a cancel event to the on_chat_cancel handler and returns its result; does nothing when no handler is set.

def dispatch_chat_cancel(event: dict)

Python · Parameters

ParameterTypeRequiredDefaultDescription
eventdictyesCancel event with conversationId, targetMessageId and agentId.

Returns void

dispatch_runtime_method

Routes a runtime method call to your handler. Raises BeeOSAgentError with status 400 for a method that is not in RUNTIME_METHODS, and with status 501 when no handler exists for it.

def dispatch_runtime_method(method: str, params: dict | None = None)

Python · Parameters

ParameterTypeRequiredDefaultDescription
methodstryesHTTP method.
paramsdict | NonenoNoneParameters of the method call; None is treated as an empty dict.

Returns void

dispatch_session_prompt

Converts the session/prompt parameters into a chat event with extract_session_prompt and passes it to the chat handler. Raises BeeOSAgentError with status 400 when the parameters are incomplete.

def dispatch_session_prompt(params: dict)

Python · Parameters

ParameterTypeRequiredDefaultDescription
paramsdictyesParameters of the session/prompt call.

Returns void

consume_envelope

Handles a message envelope: a chat_cancel envelope becomes a cancel event; any other envelope with a prompt, a message id and a conversation id becomes a chat event. Anything else is ignored and None is returned.

def consume_envelope(envelope: dict)

Python · Parameters

ParameterTypeRequiredDefaultDescription
envelopedictyesMessage envelope as received, with type, conversationId, content and related fields.

Returns void

close

Closes the runtime and clears the handlers. Later requests raise BeeOSAgentError with status 409.

def close()

Python · Parameters

No parameters.

Returns void

agent.get

Reads the agent record.

def get()

Python · Parameters

No parameters.

Returns void

agent.update_exposure

Changes the exposure settings of the agent. The current resource version is sent in If-Match, so the change fails when the record changed meanwhile.

def update_exposure(patch, resource_version)

Python · Parameters

ParameterTypeRequiredDefaultDescription
patchyesThe fields to change, as a dict.
resource_versionyesResource version of the record that the change is based on.

Returns void

agent.sync

Synchronises the agent definition with Cloud.

def sync(input)

Python · Parameters

ParameterTypeRequiredDefaultDescription
inputyesSync request body as a dict.

Returns void

messages.send

Posts a message to a conversation.

def send(conversation_id, input)

Python · Parameters

ParameterTypeRequiredDefaultDescription
conversation_idyesIdentifier of the conversation.
inputyesMessage body as a dict, with fields such as type, content and replyTo.

Returns void

messages.reply

Posts a plain-text agent_reply to an inbound message. Raises BeeOSAgentError with status 400 when a conversation id or message id is missing.

def reply(conversation_id: str, inbound_message_id: str, text: str)

Python · Parameters

ParameterTypeRequiredDefaultDescription
conversation_idstryesIdentifier of the conversation.
inbound_message_idstryesIdentifier of the message that is answered.
textstryesText of the reply.

Returns void

messages.list

Lists the messages of a conversation.

def list(conversation_id)

Python · Parameters

ParameterTypeRequiredDefaultDescription
conversation_idyesIdentifier of the conversation.

Returns void

messages.consume_envelope

Same as BeeOSAgentRuntime.consume_envelope.

def consume_envelope(envelope: dict)

Python · Parameters

ParameterTypeRequiredDefaultDescription
envelopedictyesMessage envelope as received.

Returns void

chat.patch_reply

Changes a reply message that Cloud created for a prompt, for example its body, parts or state. Raises BeeOSAgentError with status 400 when a conversation id or reply id is missing.

def patch_reply(conversation_id: str, reply_message_id: str, body: RuntimeMessagePatch, operation_key: str = '')

Python · Parameters

ParameterTypeRequiredDefaultDescription
conversation_idstryesIdentifier of the conversation.
reply_message_idstryesIdentifier of the reply message.
bodyRuntimeMessagePatchyesRequest body of the call, as JSON-compatible data.
operation_keystrno''Idempotency key, sent as Idempotency-Key. Empty means no key.

Returns void

chat.complete_reply

Finishes the reply as completed with the given text as body and as a single text part, and the stop reason end_turn.

def complete_reply(conversation_id: str, reply_message_id: str, text: str, operation_key: str = '')

Python · Parameters

ParameterTypeRequiredDefaultDescription
conversation_idstryesIdentifier of the conversation.
reply_message_idstryesIdentifier of the reply message.
textstryesFinal text of the reply.
operation_keystrno''Idempotency key, sent as Idempotency-Key. Empty means no key.

Returns void

chat.fail_reply

Finishes the reply as failed with the given body and the stop reason error.

def fail_reply(conversation_id: str, reply_message_id: str, text: str = '', operation_key: str = '')

Python · Parameters

ParameterTypeRequiredDefaultDescription
conversation_idstryesIdentifier of the conversation.
reply_message_idstryesIdentifier of the reply message.
textstrno''Body to store with the failed reply, for example an error text. Empty by default.
operation_keystrno''Idempotency key, sent as Idempotency-Key. Empty means no key.

Returns void

files.list

Lists the files of the agent.

def list()

Python · Parameters

No parameters.

Returns void

files.presign

Requests a presigned upload for a file.

def presign(input)

Python · Parameters

ParameterTypeRequiredDefaultDescription
inputyesPresign request body as a dict.

Returns void

files.confirm

Confirms that an uploaded file is complete.

def confirm(input)

Python · Parameters

ParameterTypeRequiredDefaultDescription
inputyesConfirm request body as a dict.

Returns void

files.resolve

Resolves a file id into its download information.

def resolve(file_id)

Python · Parameters

ParameterTypeRequiredDefaultDescription
file_idyesIdentifier of the file.

Returns void

canvas.token

Creates a canvas token.

def token(input=None)

Python · Parameters

ParameterTypeRequiredDefaultDescription
inputnoNoneOptional request body as a dict; an empty body is sent by default.

Returns void

a2a.discover

Discovers agents that can be called through agent-to-agent calls.

def discover()

Python · Parameters

No parameters.

Returns void

a2a.call

Calls another agent with a JSON-RPC request.

def call(agent_id, input)

Python · Parameters

ParameterTypeRequiredDefaultDescription
agent_idyesIdentifier of the agent to call.
inputyesThe JSON-RPC request as a dict.

Returns void

a2a.get_task

Reads the state of an agent-to-agent task.

def get_task(task_id)

Python · Parameters

ParameterTypeRequiredDefaultDescription
task_idyesIdentifier of the task.

Returns void

messaging.token

Creates a messaging token.

def token(input=None)

Python · Parameters

ParameterTypeRequiredDefaultDescription
inputnoNoneOptional request body as a dict; an empty body is sent by default.

Returns void

extract_chat_prompt

Python beeos_cloud_harness_sdk · Python only

Extracts a prompt from a message envelope: the text, attached files, conversation id, session key and message id. Returns None when the envelope contains no text.

def extract_chat_prompt(envelope: dict, local_agent_id: str = '') -> dict | None

Python · Parameters

ParameterTypeRequiredDefaultDescription
envelopedictyesMessage envelope as received.
local_agent_idstrno''Identifier of this agent; used to build the session key.

Returns dict \| None

extract_session_prompt

Python beeos_cloud_harness_sdk · Python only

Turns the session/prompt parameters into a chat event. Returns None when the conversation id, reply message id, task request message id or run id is missing, so that the caller can fail the operation instead of writing to an unbound reply.

def extract_session_prompt(params: dict, local_agent_id: str = '') -> dict | None

Python · Parameters

ParameterTypeRequiredDefaultDescription
paramsdictyesParameters of the session/prompt call.
local_agent_idstrno''Identifier of this agent, used when the parameters name no agent.

Returns dict \| None

BeeOSAgentError

Python beeos_cloud_harness_sdk · Python only

Error of the facade, carrying the HTTP status and a machine-readable code.

class BeeOSAgentError(RuntimeError)
def __init__(status: int, code: str, message: str)

Python · Constructor

ParameterTypeRequiredDefaultDescription
statusintyesHTTP status code of the failure.
codestryesMachine-readable error code.
messagestryesError message.

Errors and exceptions

Error types that this module defines. The description of each method says when it raises one.

ErrorsLanguageDescription
BeeOSAgentErrorPythonError of the facade, carrying the HTTP status and a machine-readable code.