Skip to main content

Overview

The @mariozechner/pi-agent-core package provides a high-level agent abstraction built on top of @mariozechner/pi-ai. It manages conversation state, executes tools automatically, handles streaming, and supports custom message types.

Stateful Agent

Manages conversation context, model, tools, and settings

Automatic Tool Execution

Validates and executes tool calls in a loop until completion

Event Streaming

Fine-grained events for UI updates (text deltas, tool execution, etc.)

Extensible Messages

Support custom message types via TypeScript declaration merging

Installation

Quick Start

Key Features

Automatic Tool Loop

The agent automatically executes tool calls until the LLM stops requesting tools:

Event System

The agent emits granular events for building responsive UIs:

State Management

The agent maintains conversation state with convenient setters:

Custom Message Types

Extend AgentMessage to support app-specific message types:

Steering and Follow-up

Interrupt or extend agent execution with queued messages:

Context Transformation

Transform conversation context before each LLM call:

Tool Streaming

Tools can stream progress updates:

Proxy Mode (Browser/Backend)

For browser apps that need to proxy LLM calls through a backend:

API Reference

Agent Class

Low-Level API

For direct control without the Agent class:

Example: Chat Bot