Skip to main content
The @mariozechner/pi-ai package defines message types and context structures for LLM conversations.

Import

Context

The conversation context passed to stream() and complete() functions.
string
required
System prompt that defines the agent’s behavior and capabilities
Message[]
required
Conversation history (user, assistant, and tool result messages)
Tool[]
Available tools the model can invoke

Example

Message Types

UserMessage

A message from the user.
'user'
required
Message role
string | Content[]
required
Message content (text or mixed content)
number
required
Timestamp in milliseconds since epoch

Example

AssistantMessage

A message from the AI assistant.
'assistant'
required
Message role
Content[]
required
Message content (text, thinking, tool calls)
Usage
Token usage statistics
number
required
Timestamp in milliseconds since epoch
string
Why generation stopped (“stop”, “length”, “tool_use”, etc.)

Example

ToolResultMessage

The result of a tool execution.
'toolResult'
required
Message role
string
required
ID of the tool call this result corresponds to
string
required
Name of the tool that was executed
Content[]
required
Tool result content
number
required
Timestamp in milliseconds since epoch
boolean
Whether the tool execution failed

Example

Content Types

TextContent

Plain text content.

ThinkingContent

Reasoning/thinking content (for extended thinking models).
boolean
Whether the thinking was redacted by safety filters

ImageContent

Image attachment.

ToolCall

Tool invocation request.

Usage

Token usage statistics.
number
Input tokens consumed
number
Output tokens generated
number
Tokens read from cache
number
Tokens written to cache
object
Cost breakdown in USD

Tool Definition

Tool definitions use JSON Schema format:

Example