Action Prompt provides a structured way to create and manage prompts for AI interactions. It enables composing messages, handling actions/tools, and managing conversation context through several key components.
Action Prompt manages the overall prompt structure including:
- Messages list with system/user/assistant roles
- Action/tool definitions
- Headers and context tracking
- Content type and encoding
- Multipart message handling
prompt = ActionPrompt::Prompt.new(
instructions: "System guidance",
message: "User input",
actions: [tool_definition, action_schema],
context: messages
)
Represents individual messages with:
message = ActionPrompt::Message.new(
content: "Search for a hotel",
role: :user
)
- Content stores the actual message text
- Role defines the message sender type (system/user/assistant/function/tool)
- Messages form interactions between roles in a Context
message = ActionPrompt::Message.new(
content: "Search for a hotel",
role: :tool,
requested_actions: [{name: "search", params: {query: "hotel"}}]
)
- Tracks if message requests actions/tools
- Maintains list of requested_actions
- Action responses include function call results
- Handles tool execution state
- Default content_type is "text/plain"
- Supports multiple content types for rich messages
- Default charset is UTF-8
- Handles content encoding/decoding
- Enforces valid roles via VALID_ROLES constant
- Validates on message creation
- Raises ArgumentError for invalid roles
- Supported roles: system, assistant, user, tool, function
message = ActionPrompt::Message.new(
content: "Hello",
role: :user,
content_type: "text/plain",
charset: "UTF-8"
)
Defines callable tools/functions:
- Name and parameters schema
- Validation and type checking
- Response handling
- Action execution
class MyAgent < ActiveAgent::Base
# Define available actions
def action_schemas
[
{name: "search", params: {query: :string}}
]
end
# Handle action responses
def perform_action(action)
case action.name
when "search"
search_service.query(action.params[:query])
end
end
end
The Base agent integrates with ActionPrompt to:
- Create prompts with context
- Register available actions
- Process action requests
- Handle responses and update context
- Manage the conversation flow
See Base.rb for full agent integration details.