Agent
Compose an agent from an identity, named capabilities, and one model adapter.
An agent is a reusable composition. Harness owns the model-and-tools loop; your application owns the provider client, services, transport, persistence, credentials, and deployment.
import { Agent, tool } from "@nylorun/harness";
import { z } from "zod";
const echo = tool({
name: "echo",
description: "Return the supplied text.",
parameters: z.object({ text: z.string() }),
execute: async ({ text }) => ({ kind: "completed", output: text }),
});
const agent = Agent({
id: "support",
name: "Support",
instructions: "Be concise and use tools when they help.",
})
.use({ id: "support-tools", tools: [echo] })
.with(adapter)
.build();id is a stable programmatic identifier and name is a display name. instructions may be one
string or an ordered list of strings.
Compose with capabilities
Pass a CapabilityDeclaration to .use() to attach model-visible instructions, tools, a model
directive, optional per-session state, and optional middleware under one stable id. The declaration
keeps each concern attributable in the resulting model configuration and observations.
Use separate capabilities for independent application services—for example, a search client, a customer record store, or approval policy. Construct those services in your host application and close over them in the capability; Harness does not construct or configure them for you.
Bind once, then build
.with(adapter) binds exactly one ModelAdapter and returns a bound builder. A bound builder only
exposes .build(), which prevents later mutation of the composition. build() is idempotent: a
successful builder returns the same BuiltAgent instance on subsequent calls.
Keep the boundary explicit
Harness validates the composition, schedules the loop, and normalizes records. Do not put API keys, database handles, HTTP routing, or deployment policy in an agent manifest or capability declaration.
Next
Choose and connect a provider in Model, then add policy and session behavior with Middleware and Session.