Getting Started

Install

Use Python 3.12+. In a macOS/Linux shell:

git clone https://github.com/ZHangZHengEric/Sage.git
cd Sage
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install -e .

On Windows, run this in PowerShell from the cloned repository root (after the git clone and cd Sage above):

py -3.12 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e .

With a newer supported Python, change the selector in the first command, for example py -3.13. Calling the venv’s python.exe directly needs neither activation nor an execution-policy change; use .\.venv\Scripts\python.exe wherever this guide runs python. Installing the dependencies needs network access.

If py -3.12 isn’t available (py -0 lists the versions the launcher knows), create the venv with the full path to an installed Python 3.12+ interpreter instead, then run the install and examples with the same .\.venv\Scripts\python.exe:

& 'C:\path\to\python.exe' -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e .

Run from one Python file

No sage.yaml file is required. SageManifestLoader.loads() parses a YAML string into a manifest, which SAgentBuilder.build() accepts directly.

Save as quickstart.py and replace your-model with a model available to your account:

"""Set MODEL_API_KEY and replace your-model below; no sage.yaml file is needed."""

from typing import cast

from sagents.v2.composition.loaded_agents import ApplicationEntrypoint

import asyncio
from uuid import uuid4

from sagents.v2 import ActorRef, RequestContext, SAgentBuilder, StartRun
from sagents.v2.contracts.commands import InputItem
from sagents.v2.contracts.items import TextBlock
from sagents.v2.contracts.principals import PrincipalType
from sagents.v2.package.manifest import SageManifestLoader

AGENT_YAML = """
schema_version: sage/v2
kind: application
metadata: {id: example.assistant, version: 1.0.0, name: Assistant}
agents:
  main:
    name: Assistant
    instructions: {inline: "Be helpful and concise."}
    models: {primary: primary}
entrypoint: {agent: main}
"""

MODELS_YAML = """
credentials:
  api-key: {source: env, key: MODEL_API_KEY}
models:
  primary:
    provider: openai-responses
    base_url: https://api.openai.com/v1
    credential: api-key
    model: your-model
"""


async def main(*, runtime=None, registrations=()):
    from sagents.v2.composition.defaults import default_runtime
    manifest = SageManifestLoader().loads(AGENT_YAML)
    builder = SAgentBuilder()
    for registration in registrations:
        builder.register(registration)
    app = await builder.build(runtime=runtime or default_runtime("runtime"), models_config_text=MODELS_YAML)
    try:
        agent = await app.load_agent(manifest)
        context = RequestContext(actor=ActorRef(
            principal_id="user-1", principal_type=PrincipalType.USER,
        ))
        stream = await cast(ApplicationEntrypoint, app.entrypoint()).run_stream(StartRun(
            agent_id=agent.id,
            input=(InputItem(role="user", content=(TextBlock(text="Say hello!"),)),),
            resolved_spec_hash=agent.composition_hash,
            idempotency_key=str(uuid4()),
        ), context, agent=agent)
        async for event in stream.events:
            print(event.model_dump_json())
        print((await stream.wait()).state)
    finally:
        await app.close()


if __name__ == "__main__":
    asyncio.run(main())
export MODEL_API_KEY="your-api-key"
python quickstart.py

This prints runtime events and the final Run state. It makes a real model request and writes Session data under runtime/. The example enables no file or shell tools. In PowerShell, set the key with $env:MODEL_API_KEY="your-api-key".

The checked-in executable example can also be run from the repository root as python -m examples.v2.quickstart.

Choose a configuration input

Input Usage
YAML string await app.load_agent(SageManifestLoader().loads(yaml_text))
Python dictionary await app.load_agent(SageManifest.model_validate(config))
Package file await app.load_agent("path/to/sage.yaml")
Resolved package await app.load_agent(resolved_manifest)

Import both manifest types from sagents.v2.package.manifest. A raw string passed directly to app.load_agent() is a path, not YAML content. String manifests should use inline instructions. File loading resolves instruction files relative to the package directory and checks that they remain inside it.

Next: configuration, tools, and runtime API.


Sage documentation for the current repository layout. Source available under the MIT license.

This site uses Just the Docs, a documentation theme for Jekyll.