Skip to content

Define an Agent

defineAgent packages behavior for a runtime host. The result is an AgentDefinition; it does not create a session, register model providers, configure storage, or start execution.

import { defineAgent } from "@harness-kernel/core/agent";
import { HarnessMode } from "@harness-kernel/core/agent/mode";
class ChatMode extends HarnessMode {
label = "Chat";
prompt = "Answer concisely and ask one clarifying question when needed.";
}
const chatMode = new ChatMode();
export const agent = defineAgent({
key: "support-agent",
label: "Support Agent",
initialMode: chatMode,
modes: [chatMode],
});
FieldOwnerNotes
keyAgentStable identity used in manifests, storage records, and status.
labelAgentHuman-readable label.
initialModeAgentMode selector used when a session starts.
modesAgentAll modes available for session.switchMode() and agent behavior.
rolesAgentCustom role definitions and built-in role overrides.
hooksAgentAgent-owned reactions to events.
declaredEventsAgentCustom event classes the package declares.
sharedStateAgentInitial state for sessions using this agent.
export const agent = defineAgent({
key: "stateful-agent",
label: "Stateful Agent",
initialMode: chatMode,
modes: [chatMode],
sharedState: {
initial: () => ({ escalations: [], productArea: "general" }),
},
});

Shared state is part of behavior because tools, hooks, context providers, and modes can read it. External databases and service clients still belong to the runtime host and should be passed through resources.

The runtime host imports the agent and gives it infrastructure:

const store = await createHarnessSessionStore({
agent: { definition: agent },
providers: [new OpenAIProvider()],
defaultModel: "openai/gpt-5.1",
});

See Session Store for host-owned configuration.