Skip to main content

Coval Agent SDK

Connect your Python voice pipeline or text agent to Coval's simulated users. Your application runs the agent; Coval records and evaluates the conversation. The SDK uses an outbound WebSocket, so your agent does not need a public endpoint.

Requires Python 3.10 or newer.

Install

python -m pip install coval-agent-sdk

Import the package as coval_agent_sdk. See the Agent SDK guide for integration details and PyPI for available versions.

Run a conversation

A run uses an SDK WebSocket agent, voice persona, and test set from the same workspace. Pass credentials and resource IDs to the client and RunConfig; this example reads them from environment variables.

The handler below echoes the caller's audio to check the connection. In an agent integration, the handler connects the audio stream to your voice pipeline.

import asyncio
import os

import coval_agent_sdk


async def on_connection(connection: coval_agent_sdk.AudioConnection) -> None:
    async for audio in connection.receive_audio():
        await connection.send_audio(audio)


async def main() -> coval_agent_sdk.RunResult:
    client = coval_agent_sdk.CovalVoiceClient(
        api_key=os.environ["COVAL_API_KEY"],
        workspace_id=os.environ["COVAL_WORKSPACE_ID"],
    )
    config = coval_agent_sdk.RunConfig(
        agent_id=os.environ["COVAL_AGENT_ID"],
        persona_id=os.environ["COVAL_PERSONA_ID"],
        test_set_id=os.environ["COVAL_TEST_SET_ID"],
        iterations=1,
        concurrency=1,
        run_timeout_seconds=600,
    )
    return await client.run(config, on_connection=on_connection)


if __name__ == "__main__":
    result = asyncio.run(main())
    print(result.run_id, result.status)

on_connection receives a ready AudioConnection. Feed receive_audio() into your pipeline and independently send its speech with send_audio(). Keep the handler active until the conversation ends, then finish conversation tasks and spans before returning. Handlers may run concurrently; keep conversation state separate.

The client defaults to https://api.coval.dev/v1. Custom api_base_url values require HTTPS. Local development may use HTTP with localhost or a loopback IP address. Configure the final API root directly. Redirects return an SDK error. See API URL validation for the accepted forms.

Audio is PCM16 little-endian, mono, 16 kHz. See the audio guide for format and buffering requirements.

Run a text conversation

Text agents use CovalTextClient with an agent whose type is MODEL_TYPE_SDK_CHAT. Each simulated-user message is one turn; reply to it with one complete send_message() call. The handler below echoes each message:

async def on_text_connection(
    connection: coval_agent_sdk.TextConnection,
) -> None:
    async for message in connection.receive_messages():
        await connection.send_message(f"You said: {message}")


async def run_text() -> coval_agent_sdk.RunResult:
    client = coval_agent_sdk.CovalTextClient(
        api_key=os.environ["COVAL_API_KEY"],
        workspace_id=os.environ["COVAL_WORKSPACE_ID"],
    )
    config = coval_agent_sdk.RunConfig(
        agent_id=os.environ["COVAL_AGENT_ID"],
        persona_id=os.environ["COVAL_PERSONA_ID"],
        test_set_id=os.environ["COVAL_TEST_SET_ID"],
    )
    return await client.run(config, on_connection=on_text_connection)

receive_messages() ends when the simulated user finishes. When the persona's conversation initiator is the agent, send your greeting with send_message() before reading. client.connect(simulation_id) attaches a text agent to one existing simulation, as for voice. Connecting the wrong client type fails before your handler runs. Text results report message counts in received_messages and sent_messages.

Trigger persona speech

On text and voice connections, await connection.trigger_persona_speech() requests a generated simulated-user turn. Pass a line to request scripted speech instead. See persona speech for support and return values.

Connect to an existing simulation

connect() attaches to one simulation without creating a run:

async def attach(
    client: coval_agent_sdk.CovalVoiceClient, simulation_id: str
) -> coval_agent_sdk.ConversationResult | None:
    async with client.connect(simulation_id) as connection:
        await on_connection(connection)
    return connection.result

Read connection.result after the context exits successfully. Leaving before voice completion raises an error. Local timeout or cancellation stops local work without cancelling the hosted run.

Serve a run you launched

When you create the run through the Coval API yourself, for example to choose metrics, test cases or run metadata that RunConfig does not cover, pass its ID to attach() instead of calling run():

result = await client.attach(run_id, on_connection, run_timeout_seconds=900)

attach() creates no run; it discovers and serves the run's conversations with the same monitoring, session isolation and results as run(). Both clients provide it.

Results and errors

RunResult contains the run ID, hosted status, completed conversations, and SDK session failures. Each ConversationFailure retains the simulation ID, exception type and diagnostic message. Each ConversationResult includes its simulation ID, audio byte counts, and optional trace delivery result. Execution completion does not mean the agent passed its evaluation criteria.

Catch CovalError for SDK failures. A failed voice session is isolated while the SDK continues attaching and serving unrelated conversations. After the batch finishes, RunError.result retains the run ID, last observed status, completed conversations, and per-session failures. Authentication/authorization errors, global monitoring errors and the batch deadline still stop local work promptly. Application exceptions and cancellation propagate unchanged. See Developer API for result types and argument validation.

Tracing

python -m pip install "coval-agent-sdk[tracing]"

Share one CovalTraceExporter between your OpenTelemetry provider and CovalVoiceClient(trace_exporter=...). Correlate the conversation root with connection.simulation_id and finish spans before the handler returns. The tracing guide includes a setup example.

Terraform

Manage test configuration with Terraform and pass the resulting resource IDs to the SDK. Use Coval to review recordings, evaluations, and traces.

Contributing

CONTRIBUTING.md covers setup, tests, and review. See local development, Python conventions, and architecture for contributor guidance. CHANGELOG.md records releases; SECURITY.md explains private vulnerability reporting.

License

Copyright 2026 Coval, Inc. Licensed under the Apache License, Version 2.0. See NOTICE for attribution.

Metadata

Release files for coval-agent-sdk 0.3.1

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

Source distribution (sdist)

Source distribution for coval-agent-sdk 0.3.1
File Size Uploaded Provenance Actions
coval_agent_sdk-0.3.1.tar.gz 103.6 kB With provenance Details for coval_agent_sdk-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for coval-agent-sdk 0.3.1
File Interpreter ABI Platform Actions
coval_agent_sdk-0.3.1-py3-none-any.whl Python 3 none any Details for coval_agent_sdk-0.3.1-py3-none-any.whl

Total release size: 144.8 kB

Release files / coval_agent_sdk-0.3.1.tar.gz

Download URL coval_agent_sdk-0.3.1.tar.gz
Size 103.6 kB
Tags Source
SHA-256 checksum
How to use checksums
be3c7f241c04d194068ae96606b444de76d93f77aed6fd59b8f23c589c5d450b
BLAKE2b-256 checksum
How to use checksums
bf5f01b2060235d01279832c5c1fcbde7294dde0c1c3f968163af975d51cffc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / coval_agent_sdk-0.3.1-py3-none-any.whl

Download URL coval_agent_sdk-0.3.1-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
746e96f8ca6dc7e99af13f3c011c364a4e43fef9239e1d299cdf15753babcc42
BLAKE2b-256 checksum
How to use checksums
cc1fbb35bfbb46a9c0256947cbd871d54f391e306d6080a2378dccec4ed96012
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for coval-agent-sdk 0.3.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for coval_agent_sdk-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

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.

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