Agent Lifecycle
Construct, ready, execute, and dispose an Agent
new Agent(options) creates only the Agent identity, model, instructions, custom Tools, Session collection, and ActionSchedule. Powers do not belong to Agent. After City registers the Agent, it projects City-owned Power capabilities into the Agent execution entry.
Run only one active runtime for the same Agent ID in the same physical Workspace. ActionSchedule is a local scheduler and does not coordinate duplicate Agent processes.
import { Agent } from "@downcity/agent";
import { City, Shell, Workspace } from "@downcity/city";
import { MicrosandboxProvider } from "@downcity/sandbox-microsandbox";
const shell = new Shell({ sandbox_provider: new MicrosandboxProvider() });
const agent = new Agent({
id: "my-agent",
model,
});
const workspace = new Workspace({
id: "project",
path: process.cwd(),
shell,
});
const city = new City({ agents: [agent], workspaces: [workspace] });
const session = await agent.sessions.create({ workspace });
const turn = await session.prompt({ query: "Start" });
await turn.finished;
await city.close();Sessions wait until the Agent's City execution binding is ready. agent.dispose() releases only Agent-owned Sessions, ActionSchedule, and execution bindings. city.close() first stops Agent Sessions, then stops the single City-owned Power instances and closes Workspaces, Shells, and Transports.
Continue with the Agent SDK docs.