# Interface IAgent

Base interface for all agents.

interface IAgent {
id: string;
role: AgentRole;
state: AgentState;
capabilities: readonly AgentCapability[];
execute(task: Task): Promise<Result<TaskResult, AgentError>>;
handleMessage(
msg: AgentMessage,
): Promise<Result<AgentResponse, AgentError>>;
initialize(ctx: AgentContext): Promise<Result<void, AgentError>>;
cleanup(): Promise<void>;
}

#### Implemented by

- BaseAgent

- Defined in packages/nexus-agents/src/core/types/agent.ts:208

##### Index

### Properties

id
role
state
capabilities

### Methods

execute
handleMessage
initialize
cleanup

## Properties

### `Readonly` id

id: string

Unique agent identifier

- Defined in packages/nexus-agents/src/core/types/agent.ts:210

### `Readonly` role

role: AgentRole

Agent role

- Defined in packages/nexus-agents/src/core/types/agent.ts:213

### `Readonly` state

state: AgentState

Current state

- Defined in packages/nexus-agents/src/core/types/agent.ts:216

### `Readonly` capabilities

capabilities: readonly AgentCapability[]

Agent capabilities

- Defined in packages/nexus-agents/src/core/types/agent.ts:219

## Methods

### execute

- execute(task: Task): Promise<Result<TaskResult, AgentError>>

  Execute a task.

  #### Parameters

  - task: Task

    Task to execute

  #### Returns Promise<Result<TaskResult, AgentError>>

  Result with TaskResult or AgentError

  - Defined in packages/nexus-agents/src/core/types/agent.ts:226

### handleMessage

- handleMessage(msg: AgentMessage): Promise<Result<AgentResponse, AgentError>>

  Handle an inter-agent message.

  #### Parameters

  - msg: AgentMessage

    Message to handle

  #### Returns Promise<Result<AgentResponse, AgentError>>

  Result with AgentResponse or AgentError

  - Defined in packages/nexus-agents/src/core/types/agent.ts:233

### initialize

- initialize(ctx: AgentContext): Promise<Result<void, AgentError>>

  Initialize the agent with context.

  #### Parameters

  - ctx: AgentContext

    Agent context

  #### Returns Promise<Result<void, AgentError>>

  Result with void or AgentError

  - Defined in packages/nexus-agents/src/core/types/agent.ts:240

### cleanup

- cleanup(): Promise<void>

  Cleanup agent resources.

  #### Returns Promise<void>

  - Defined in packages/nexus-agents/src/core/types/agent.ts:245