aiAgent

Create an autonomous AI Agent that can reason, use tools, maintain memory, and execute multi-step tasks.

🔄 Agent Execution Flow

Syntax

aiAgent(name, description, instructions, model, memory, tools, subAgents, params, options)

Parameters

Parameter
Type
Required
Default
Description

name

string

No

"BxAi"

The agent's name/identifier

description

string

No

""

The agent's role or purpose description

instructions

string

No

""

System instructions for agent behavior

model

AiModel

No

aiModel()

The AI model provider to use

memory

any

No

aiMemory()

Single IAiMemory instance or array of memories

tools

array

No

[]

Array of Tool objects the agent can use

subAgents

array

No

[]

Array of sub-agents for task delegation

params

struct

No

{}

Additional provider parameters (temperature, max_tokens, etc.)

options

struct

No

{}

Additional options (timeout, logging, etc.)

Returns

Returns an AiAgent instance with fluent API for:

  • Running conversations: run(input)

  • Streaming responses: stream(callback, input)

  • Tool management: addTool(), removeTool()

  • Memory management: addMemory(), getMemory()

  • Pipeline integration: Agents are IAiRunnable

Examples

Basic Agent

Agent with Instructions

Agent with Tools

Agent with Memory

Agent with Multiple Memories

Sub-Agents (Delegation)

Streaming Agent

Pipeline Integration

Custom Model and Parameters

Agent Capabilities

Agents are autonomous entities that can:

🧠 Reasoning

  • Analyze complex problems

  • Plan multi-step solutions

  • Make decisions based on context

🔧 Tool Usage

  • Automatically select and use tools

  • Chain tool calls for complex tasks

  • Handle tool results intelligently

💾 Memory

  • Maintain conversation history

  • Retrieve relevant context from vector memory

  • Support multiple memory types simultaneously

🎯 Task Execution

  • Execute multi-step workflows

  • Retry on failures

  • Track progress and state

🤝 Delegation

  • Delegate tasks to specialized sub-agents

  • Coordinate between multiple agents

  • Combine capabilities

Notes

  • Autonomous execution: Agents decide when to use tools, search memory, or respond directly

  • Automatic memory search: Vector memories are automatically searched for relevant context

  • Tool selection: Agent analyzes task and selects appropriate tools

  • Sub-agent registration: Sub-agents are automatically converted to callable tools

  • Conversation state: Window/session memories maintain conversation context automatically

  • Event hooks: Announces onAIAgentCreate event for custom logic

Best Practices

Last updated