Docs

    SDK reference

    Python SDK

    EvalKit for Python: sessions and named agents, the Eval() rows that agent evaluators read, scenario simulation with a live simulated user, voice bots, and a summary of errors, health and shutdown.

    EvalKit for Python is the syntropylabs-evalkit package, imported as evalkit. Most of this reference is still being written; sessions, agents, the Eval() rows that agent evaluators read and scenario simulation are documented below, with a summary of errors, health and shutdown. Every init() option is on Configuration and privacy.

    Sessions and agents

    A session is one conversation. Every span opened inside evalkit.session(...) belongs to that session. An agent is the name you give your agent in code. After evalkit.set_agent(...), every trace carries that name, and Traces → Agents shows the agent's sessions, versions and verdicts. You never declare a version: the trace service detects it from the model, system prompt, tools, temperature and top-p.

    Python
    import evalkit
    
    evalkit.set_agent("support-bot")                 # every trace after this belongs to support-bot
    
    with evalkit.session("conv_55", user_id="u_8123"):
        answer = agent.run(message)
    
    @evalkit.session("conv_55")                      # also a decorator, sync or async
    async def handle_turn(message): ...
    
    trace_id, end, ctx = evalkit.start_trace("turn", agent="planner")                   # one trace only
    end_step, _ = evalkit.start_span("research", {"gen_ai.agent.name": "researcher"})  # a sub-agent
    • On exit, the session and user that were in force before the block come back. Concurrent requests and tasks never see each other's session. user_id is optional.
    • set_agent is scoped like set_user, per thread and per asyncio task. It returns a token that evalkit.clear_agent(token) uses to restore the previous name. evalkit.current_agent() reads the current name.
    • Spans carry the agent as evalkit.agent_name and gen_ai.agent.name. A span that already carries session.id, conversation.id, gen_ai.conversation.id or evalkit.session_id keeps its own session.
    • From 0.3.1, OpenAI chat, OpenAI Responses and Anthropic calls record the names of the tools they were given in gen_ai.request.tools, built-in tools such as web_search included. They also record temperature, top_p and the max-tokens setting, so a change of tools or sampling shows as a new version. An Anthropic system prompt given as a list of blocks is recorded as its text. Right after the upgrade, each agent configuration starts one new version, because these parameters are now part of it.

    Eval() rows for agent evaluators

    Agent evaluators such as Step Efficiency, Argument Correctness and Role Adherence read the agent's turns and tool calls. A row with only text skips them with the reason "This row has only text. Pass trace_id, session_id or messages to evaluate the agent's turns and tool calls." A row gives them what they read by pointing at a recorded trace or session, or by carrying the conversation:

    Python
    rows = [
        # A session or trace already recorded in the key's project and Environment
        {"input": "Refund order 1001", "output": reply, "session_id": "conv_55"},
        {"input": "Where is order 1002?", "output": answer, "trace_id": trace_id},
        # The conversation itself, in OpenAI chat format
        {"input": "Refund order 1001", "output": reply,
         "messages": messages,                        # user, assistant (with tool_calls) and tool messages
         "tools": tools,                              # OpenAI tool definitions with JSON Schema parameters
         "system_prompt": system_prompt},             # optional, like tools
    ]
    evalkit.flush()                                   # send the recorded spans before the run is scored
    evalkit.Eval("agent-regression", data=rows, evaluators=[STEP_EFFICIENCY_ID, ROLE_ADHERENCE_ID])
    • From 0.3.3, trace_id, session_id, messages, tools and system_prompt are row keys of their own, as above. The SDK checks them before the run opens: an empty id, or messages or tools that is not a list, raises TypeError or ValueError naming the row. With 0.3.2, put the same keys in metadata, such as "metadata": {"session_id": "conv_55"}. The server reads either place, and a top-level key wins over its metadata twin.
    • From a trace or session, the server builds the turns, the tool calls with their arguments and results, the declared tools and the system prompt. If the trace has not arrived when the run is scored, the agent evaluators skip that row with a reason that says so.
    • input, output and expected still feed the row-level evaluators. Turns in the results are numbered from 1. See Runs from code for a whole conversation row.

    Scenario simulation

    generate_scenarios() has the server write scenarios for your agent, simulate_user() plays them against your agent in your own process, and evaluate_simulation() grades the run with an evaluator collection. The server side needs a plan with simulations.

    Python
    scenarios = evalkit.generate_scenarios(
        "You are a billing support agent.",
        tools=["lookup_order", "issue_refund"],
        count=5,
    )
    
    def entrypoint(ctx: evalkit.SimContext) -> evalkit.AgentTurnResult:
        reply, calls = run_my_agent(ctx.session_id, ctx.message)   # one turn of your agent
        # calls: [{"name": "issue_refund", "arguments": {...}, "result": {...}}], or "error" for a failed call
        return evalkit.AgentTurnResult(text=reply, tool_calls=calls)
    
    report = evalkit.simulate_user(
        entrypoint,
        scenarios,
        agent="billing-bot",       # names the agent under test on every span of the run
        user_model="sim-user",     # the Model the simulated user runs on, by name or id
        max_turns=8,
    )
    for result in report["results"]:
        print(result["name"], result["status"], result.get("ended_by"))
    OptionDefaultWhat it does
    max_turns12The most user turns one scenario plays. The live user plays at most 50, whatever this says.
    user_modelmodelThe Model of your organization the simulated user runs on, by its name or id. A live scenario without one fails with "No model is configured for the simulated user".
    live_useron for a scenario with a user_goal or conversation_plan and no turnsTrue plays the live user after the scripted turns of any scenario. False replays the scripted turns only.
    agentnoneNames the agent under test on every span of the run, so the run lists under that agent
    metricsallThe deterministic metrics each scenario is scored with in your process
    tags, safe_modenone, TrueLabels for the run; safe_mode is copied into ctx.state["__safe_mode__"] for your agent to guard side effects
    • After the scripted turns, or from the opening message when a scenario has none, the platform plays the user from the scenario's persona, user_goal, hidden_info and tool answers, reading the conversation so far. It stops once its goal is met or max_turns user turns were played.
    • The tool calls an AgentTurnResult reports, with their result or error, tell the user what actually happened, such as a refund the agent says it issued that its tool refused. The user reacts only to what the agent says and never quotes them.
    • Each user turn is a simulated_user span marked evalkit.simulation.role: user, under the scenario's root. Evaluations never read it as the agent's turn, tool call or output.
    • A live scenario's result also carries transcript (the conversation as role and content messages), ended_by (user, max_turns or error) and simulated_user_usage (calls, input_tokens, output_tokens and cost_usd, which is None when the Model has no price).
    • If the user cannot play a turn, the scenario ends with status ERROR and the platform's reason.

    The simulated user runs on your organization's Model, so its calls are billed to your provider account. Their cost is recorded per Environment and shows on Cost as Simulated user. The platform plays at most 50 user turns of one scenario, answers 120 user-turn requests a minute per Environment, and plays 5,000 simulated user turns per organization per UTC day; past that it answers 429 until midnight UTC.

    generate_scenarios() writes briefs for the live user: each scenario carries its persona, user_goal, hidden_info (facts the user shares only once the agent asks about them), success_criteria and its opening message in starting_prompt, and no later turns. Pass scripted_turns=True for scenarios with every user turn written out in turns, to replay a conversation word for word.

    Errors, health and shutdown

    Python
    evalkit.init(
        subscription_key=os.environ["EVALKIT_SUBSCRIPTION_KEY"],
        sample_rate=0.25,           # a quarter of traces; model calls, tool calls and errors are always kept
        capture_unhandled=True,     # also record exceptions nothing in the app caught
        in_app_include=["acme"],    # module prefixes that are your own code in an exception's frames
    )
    
    token = evalkit.set_error_fingerprint("checkout-timeout")   # group the errors recorded from here on
    evalkit.clear_error_fingerprint(token)
    
    evalkit.stats()               # queued, exported and dropped spans, the last error, the circuit's state
    evalkit.flush(timeout=2.0)    # send now, waiting at most 2 seconds; True when everything was taken

    Voice bots

    From 0.3.8, the Python SDK traces voice bots built on Pipecat and LiveKit Agents (evalkit.instrument_pipecat, evalkit.instrument_livekit_agents) and installs evalkit voice-test, which calls a bot over its WebSocket and gates CI on the result. From 0.3.9 its callers are written from a description of the bot (--about) and talk to it towards a goal, answering what it says; scenarios files of goals or exact lines and your own keys for the caller came with it too. They need the voice extra, pip install "syntropylabs-evalkit[voice]>=0.3.9". See Test a voice bot and Trace a voice bot.

    From 0.3.9, a call to the SyntropyLabs API that the server refuses, such as generate_scenarios() with a bad request, raises evalkit.ApiError. It is an urllib.error.HTTPError whose message is the call, the status and the server's reason, with status, server_message, response_text and retry_after; your keys are kept out of it.

    EvalKit is built by SyntropyLabs. Published on PyPI and npm.