Polka Docs

Your first agent

An agent is a Rust package. It has one function that builds its harness from a Setup, and the places it runs call that function: the terminal, the edge, a host.

The ADK's examples/runner is the smallest complete one. It does small programming tasks in a folder of its own.

The package

runner/
  Cargo.toml
  src/
    agent.rs    the agent: Setup in, a Harness out
    lib.rs      the same agent as an edge module
    main.rs     the same agent in the terminal

Cargo.toml builds both a library (for the edge) and a program (for the terminal). The terminal's front is left out of the WebAssembly build:

[package]
name = "runner"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
edge.workspace = true
harness.workspace = true
runtime.workspace = true
tools.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
front.workspace = true

The examples live in the ADK's workspace, so they name the crates with .workspace = true. A package of your own outside it names them by git:

harness = { git = "https://github.com/sujancode/polka-adk" }

While the repository is private, cargo needs your git login for that: CARGO_NET_GIT_FETCH_WITH_CLI=true.

The agent

use std::sync::Arc;

use harness::{Harness, Model, Prompt};
use runtime::{Result, Setup};

const MODEL: &str = "@cf/openai/gpt-oss-120b";
const WHO: &str = "You do small programming tasks in a folder of your own: write the code, run it to check it, and answer in one or two sentences with what it printed.";

pub fn agent(setup: &Setup) -> Result<Harness<Arc<dyn Model>>> {
    let sandbox = setup.sandbox(setup.workspace())?;
    let prompt = Prompt::new().text(WHO).section("Environment", setup.environment());
    Ok(Harness::new(setup.model(), setup.model_id(MODEL))
        .system(prompt)
        .tools(tools::all(sandbox))
        .max_output_tokens(4096)
        .max_steps(10))
}

Setup is what the place it runs gives it:

Setup gives In the terminal On the edge
model() the gateway, with your login the platform's gateway, with the version's own key
model_id(default) --model, or your default the environment's model, or your default
sandbox(root) a folder on this machine, confined a fresh container for this task
environment() what the machine is, for the prompt what the box is, for the prompt

Where it runs

src/lib.rs makes the same function the edge module:

mod agent;

pub use agent::agent;

edge::agent!(agent::agent);

src/main.rs gives it the terminal:

use std::process::ExitCode;

use front::{Serve, Terminal};

fn main() -> ExitCode {
    Terminal.serve(runner::agent)
}

Talk to it

polka chat examples/runner

polka chat builds the package with cargo, logs it in with your login and starts it. Type to talk; type while it works to steer it; /stop or ctrl-c stops the turn. Each conversation is kept as an append-only log: --resume carries on the last one, --fork <id> starts a new one from a copy.

Next

Edit this page on GitHub