### Install ActiveAgent Gem Manually Source: https://docs.activeagents.ai/docs/getting-started Installs the `activeagent` gem directly using the `gem install` command. This method is useful for standalone installation or when not managing dependencies via Bundler. ```bash $ gem install activeagent ``` -------------------------------- ### Install Ruby Gems with Bundler Source: https://docs.activeagents.ai/docs/getting-started Executes `bundle install` to download and install the gems specified in the Gemfile. This command resolves all dependencies and makes the installed libraries available to your Ruby application. ```bash $ bundle install ``` -------------------------------- ### Configure ActiveAgent Generation Providers in YAML Source: https://docs.activeagents.ai/docs/getting-started Provides an example `config/active_agent.yml` file for configuring various AI generation providers across different environments (development, test). This YAML structure allows you to define service-specific settings such as API keys, host URLs, models, and temperatures for providers like OpenAI, OpenRouter, and Ollama. ```yaml # This file is used to configure the Active Agent Generation Providers for different environments. # Each provider can have its own settings, such as API keys and model configurations. # Make sure to set the API keys in your Rails credentials for each generation provider before using them # in your agent's `generate_with` config. openai: &openai service: "OpenAI" api_key: <%= Rails.application.credentials.dig(:openai, :api_key) %> open_router: &open_router service: "OpenRouter" api_key: <%= Rails.application.credentials.dig(:open_router, :api_key) %> ollama: &ollama service: "Ollama" api_key: "" host: "http://localhost:11434" model: "gemma3:latest" temperature: 0.7 development: openai: <<: *openai model: "gpt-4o-mini" temperature: 0.7 open_router: <<: *open_router model: "qwen/qwen3-30b-a3b:free" temperature: 0.7 ollama: <<: *ollama test: openai: <<: *openai model: "gpt-4o-mini" temperature: 0.7 open_router: <<: *open_router model: "qwen/qwen3-30b-a3b:free" temperature: 0.7 ollama: <<: *ollama ``` -------------------------------- ### Generate ActiveAgent Configuration in Rails Source: https://docs.activeagents.ai/docs/getting-started Runs the Active Agent install generator in a Rails application. This command creates essential configuration files like `config/active_agent.yml` and sets up necessary directories (`app/agents`, `app/views/agent_*`) for agent classes and prompt templates. ```bash $ rails generate active_agent:install ``` -------------------------------- ### Interact with Application Agent for Text Prompt Generation Source: https://docs.activeagents.ai/docs/getting-started Demonstrates how to dynamically parameterize and interact with the `ApplicationAgent` instance. It sets instructions, defines available actions, and provides initial user messages, then triggers the AI generation process to produce a text prompt. ```ruby ApplicationAgent.with( instructions: "Help users with their queries.", actions: [:weather], messages: [ { role: 'user', content: 'What is the weather like today?' } ] ).text_prompt.generate_now ``` -------------------------------- ### Initialize and Generate Response with TravelAgent Source: https://docs.activeagents.ai/docs/getting-started This Ruby code demonstrates basic usage of the `TravelAgent` by initializing it with specific instructions and a user message. It then calls `generate_later` to process the context and generate a response based on the agent's defined actions. ```ruby TravelAgent.with( instructions: "Help users with travel-related queries, using the search, book, and confirm actions.", messages: [ { role: 'user', content: 'I need a hotel in Paris' } ] ).generate_later ``` -------------------------------- ### Add ActiveAgent and Generation Provider Gems Source: https://docs.activeagents.ai/docs/getting-started Adds the `activeagent` gem and a chosen generation provider gem (e.g., `ruby-openai`) to your application's Gemfile for dependency management. This prepares your project to use ActiveAgent's core functionalities and integrate with an AI model service. ```bash # Add this line to your application's Gemfile gem 'activeagent' # Add the generation provider gem you want to use, e.g.: gem 'ruby-openai' ``` -------------------------------- ### Define Base ApplicationAgent Class Source: https://docs.activeagents.ai/docs/getting-started This Ruby code defines the `ApplicationAgent` class, which serves as the base class for all agents in the application. It configures the default generation provider (OpenAI), specifies instructions, model, and temperature for agent behavior. ```ruby class ApplicationAgent < ActiveAgent::Base generate_with :openai, instructions: "You are a helpful assistant.", model: "gpt-4o-mini", temperature: 0.7 # This is the base class for all agents in your application. # You can define common methods and configurations here. end ``` -------------------------------- ### Define TravelAgent Class with Actions Source: https://docs.activeagents.ai/docs/getting-started This Ruby code defines the `TravelAgent` class, inheriting from `ActiveAgent::Base`. It includes placeholder methods for `search`, `book`, and `confirm` actions, demonstrating the structure generated for a new agent with specified functionalities. ```ruby class TravelAgent < ActiveAgent::Base def search # Your search logic here prompt end def book # Your booking logic here prompt end def confirm # Your confirmation logic here prompt end end ``` -------------------------------- ### Define Base Application Agent with OpenAI Provider Source: https://docs.activeagents.ai/docs/getting-started Defines an `ApplicationAgent` class that inherits from `ActiveAgent::Base`, establishing the foundation for your application's agent. It configures the agent to use OpenAI as the generation provider, specifying the model (`gpt-4o-mini`), instructions, and temperature for AI responses. ```ruby class ApplicationAgent < ActiveAgent::Base generate_with :openai, instructions: "You are a helpful assistant.", model: "gpt-4o-mini", temperature: 0.7 end ``` -------------------------------- ### Define TravelAgent Search Action ERB HTML View Source: https://docs.activeagents.ai/docs/getting-started This ERB snippet provides the HTML view template for the `search` action of the `TravelAgent`. It renders a form for users to input a location, demonstrating how web-friendly content can be generated for agent actions. ```erb

Search for Travel Options

Enter the location you want to search for:

``` -------------------------------- ### Configure OpenAI Generation Provider Host Source: https://docs.activeagents.ai/docs/getting-started This YAML snippet demonstrates how to configure a custom host and API key for the OpenAI generation service within an Active Agents application. It allows specifying a custom endpoint, such as an Azure OpenAI resource, for the AI model. ```yaml openai: &openai service: "OpenAI" api_key: <%= Rails.application.credentials.dig(:openai, :api_key) %> host: "https://your-azure-openai-resource.openai.azure.com" ``` -------------------------------- ### Define TravelAgent Search Action JSON Tool Schema Source: https://docs.activeagents.ai/docs/getting-started This JSON snippet defines the tool schema for the `search` action of the `TravelAgent`. It specifies the tool's name, description, and required parameters, enabling the agent to understand and utilize the `location` input for searching travel options. ```json { "tool": { "name": "search", "description": "Search for travel options", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The location to search for travel options" } }, "required": ["location"] } } } ``` -------------------------------- ### Generate New Active Agent with Rails Generator Source: https://docs.activeagents.ai/docs/getting-started This Bash command uses the Rails generator to create a new Active Agent class named `TravelAgent`. It also defines specific actions (`search`, `book`, `confirm`) that will be implemented as methods within the agent class, along with corresponding view templates. ```bash $ rails generate active_agent:agent TravelAgent search book confirm ``` -------------------------------- ### Implementing a Translation Agent with OpenAI and Jbuilder Source: https://docs.activeagents.ai/docs/framework/active-agent This example demonstrates how to create a `TranslationAgent` in Ruby, configure it with OpenAI for text translation, and define its action's input schema using a Jbuilder template. It also shows a simple ERB template for constructing the translation prompt. ```ruby class TranslationAgent < ApplicationAgent generate_with :openai, instructions: "Translate the given text from one language to another." def translate prompt(messages: params[:messages], context_id: params[:context_id]) end end ``` ```json json.type :function json.function do json.name action_name json.description "This action takes params locale and message and returns a translated message." json.parameters do json.type :object json.properties do json.locale do json.type :string json.description "The target language for translation." end json.message do json.type :string json.description "The text to be translated." end end end end ``` ```erb translate: <%= params[:message] %>; to <%= params[:locale] %> ``` -------------------------------- ### Creating an Active Agent Prompt Manually Source: https://docs.activeagents.ai/docs/action-prompt/prompts This Ruby example demonstrates how to manually construct an `ActiveAgent::ActionPrompt::Prompt` instance. It shows how to explicitly define the prompt's actions, a single current message, and an array of historical messages to build the contextual history for a generation provider. ```ruby prompt = ActiveAgent::ActionPrompt::Prompt.new( actions: SupportAgent.new.action_schemas, message: "I need help with my account.", messages: [ { content: "Hello, how can I assist you today?", role: "assistant" }, ] ) ``` -------------------------------- ### Rendering an Active Agent Prompt Context Source: https://docs.activeagents.ai/docs/action-prompt/prompts This Ruby example illustrates how to render a prompt using the `prompt_context` method on an agent instance. It demonstrates passing an initial message and historical messages to generate the structured prompt object, which encapsulates the necessary context for the generation provider. ```ruby agent_prompt_context = SupportAgent.with(message: "I need help with my account.", messages: [ { content: "Hello, how can I assist you today?", role: :assistant }, ]).prompt_context ``` -------------------------------- ### Example System Message for Agent Instructions (ERB) Source: https://docs.activeagents.ai/docs/action-prompt/messages This ERB template demonstrates how a `:system` message can be structured to provide instructions to an Active Agent. It includes dynamic content like the user's name and a list of available actions with their descriptions, along with specific requirements for the agent's behavior. ```erb This agent is currently interacting with <%= @user.name %> to find a hotel near their travel destination. The agent should use the following actions to achieve the desired outcome: <% actions do |action| %> <%= action.name %>: <%= action.description %> <% end %> requirements: - The agent should use the `:search` action to find hotels in the requested location. - The agent should use the `:book` action to book a hotel for the user. - The agent should use the `:confirm` action to confirm the booking with the user. ``` -------------------------------- ### Configure OpenRouter Generation Provider for Active Agent Source: https://docs.activeagents.ai/docs/framework/generation-provider Example of configuring an `ApplicationAgent` to use OpenRouter as its generation provider, including a specific model and instructions. ```ruby class OpenRouterAgent < ApplicationAgent layout "agent" generate_with :open_router, model: "qwen/qwen3-30b-a3b:free", instructions: "You're a basic Open Router agent." end ``` -------------------------------- ### Implementing a Travel Agent with Multiple Content Type Views Source: https://docs.activeagents.ai/docs/framework/active-agent This example showcases a `TravelAgent` in Ruby that handles different user interactions by rendering responses in various content types (HTML, JSON, and plain text). It demonstrates how to define agent actions and corresponding view templates for each content type. ```ruby class TravelAgent < ApplicationAgent def search prompt(message: params[:message], content_type: :html) end def book prompt(message: params[:message], content_type: :json) end def confirm prompt(message: params[:message], content_type: :text) end end ``` ```html <%# app/views/travel_agent/search.html.erb %>

Search Results

<%= @prompt.message %>

``` ```json { "message": "<%= @prompt.message %>", "results": <%= @prompt.results.to_json %> } ``` ```text <%# app/views/travel_agent/confirm.text.erb %> Your booking has been confirmed! Booking ID: <%= @prompt.booking_id %> Thank you for choosing our service. ``` -------------------------------- ### Access Attributes of Active Agent Generation Response Object Source: https://docs.activeagents.ai/docs/framework/generation-provider Provides Ruby examples demonstrating how to access various attributes of the `ActiveAgent::GenerationProvider::Response` object, including the message, prompt, and raw response data, following an agent configuration. ```ruby class ApplicationAgent < ActiveAgent::Base layout "agent" generate_with :openai, model: "gpt-4o-mini", instructions: "You're just a basic agent", stream: true end ``` ```ruby # Access the response message puts response.message # Inspect the prompt that was sent puts response.prompt.inspect # Access the messages in the prompt puts response.prompt.messages.inspect # Debug with raw response data puts response.raw_response.inspect ``` -------------------------------- ### Handling On-Stream Callbacks for Real-time Updates in Active Agent Source: https://docs.activeagents.ai/docs/active-agent/callbacks Provides a verbose example of `on_stream` callback usage to handle real-time updates during response streaming. It shows how to broadcast partial messages to a chat interface, demonstrating dynamic content updates and interaction with the agent's `generation_provider` and its `response` object. ```ruby class ApplicationAgent < ActiveAgent::Base generate_with :openai on_stream :broadcast_message private def broadcast_message @chat ||= Chat.find(generation_provider.prompt.context_id) # Create or find the assistant message @message ||= @chat.messages.create(content: "", role: 'assistant') # Update the message content with the streaming content @message.update(content: generation_provider.response.message.content) puts "Broadcasting message... #{generation_provider.response.message.content}" # Handle broadcasting directly here instead of relying on model callbacks if @message.persisted? if @message.content.present? # Broadcast the updated message during streaming @message.broadcast_append_to( "#{ActionView::RecordIdentifier.dom_id(@chat)}_messages", partial: "messages/message", locals: { message: @message, scroll_to: true }, target: "#{ActionView::RecordIdentifier.dom_id(@chat)}_messages" ) end end end ``` -------------------------------- ### Active Agent Framework Overview Source: https://docs.activeagents.ai/docs/index Active Agent is built around core components that provide a seamless experience for developers. It extends familiar concepts from Rails MVC to AI and generative models, with Action Prompt managing prompts, actions, and responses. The framework is modular and extensible for creating custom agents. ```APIDOC Framework Components: - Active Agent: Core framework for AI applications. - Action Prompt: Manages prompts, actions, and responses. - Generation Provider: Interfaces with AI models (e.g., OpenAI, Anthropic). Key Concepts: - Agent Oriented Programming: Modular and reusable AI components. - MVC Architecture: Extends Rails concepts to AI development. Functionality: - Structured prompt management. - Modular agent creation. - Extensible design for custom actions and responses. ``` -------------------------------- ### Configure OpenAI Generation Provider for Active Agent Source: https://docs.activeagents.ai/docs/framework/generation-provider Demonstrates how to configure an `ApplicationAgent` to use OpenAI as its generation provider, specifying a model and initial instructions. ```ruby class OpenAIAgent < ApplicationAgent layout "agent" generate_with :openai, model: "gpt-4o-mini", instructions: "You're a basic OpenAI agent." end ``` -------------------------------- ### Prompt Method Configuration Options (APIDOC) Source: https://docs.activeagents.ai/docs/action-prompt/actions This section details the available parameters when calling the `prompt` method within an agent. These options control how the agent's response is rendered and what contextual information is included in the prompt. ```APIDOC prompt options: content_type: Specifies the type of content to be rendered (e.g., :text, :json, :html). message: The message.content to be displayed in the prompt. messages: An array of messages objects to be included in the prompt's context. template_name: Specifies the name of the template to be used for rendering the action's response. ``` -------------------------------- ### Configure Google Generation Provider for Active Agent Source: https://docs.activeagents.ai/docs/framework/generation-provider Illustrates how to set up an `ApplicationAgent` to utilize Google as its generation provider. ```ruby class ApplicationAgent < ActiveAgent::Base generate_with :google end ``` -------------------------------- ### Configure Ollama Generation Provider for Active Agent Source: https://docs.activeagents.ai/docs/framework/generation-provider Demonstrates configuring an `ApplicationAgent` to use Ollama as its generation provider, specifying a model and instructions. ```ruby class OllamaAgent < ApplicationAgent layout "agent" generate_with :ollama, model: "gemma3:latest", instructions: "You're a basic Ollama agent." end ``` -------------------------------- ### Synchronous Prompt Generation with ApplicationAgent Source: https://docs.activeagents.ai/docs/active-agent/generation Illustrates the immediate generation of a prompt using the `generate_now` method. This method, invoked on an `ApplicationAgent` instance with a specified message, processes the prompt context and returns the AI-generated response synchronously. ```ruby message = "Test Application Agent" response = ApplicationAgent.with(message: message).prompt_context.generate_now ``` -------------------------------- ### Prompt Context Model Source: https://docs.activeagents.ai/docs/index Prompt Context is the core data model in Action Prompt, containing runtime context, messages, variables, and configuration for prompts. It manages contextual history and provides information for prompt/response cycles. Callbacks enable contextual prompting, retrieval, generation response handling, and persistence. ```APIDOC Prompt Context (Model): Purpose: Core data model for runtime prompt information. Data: - messages: Runtime context messages. - actions: Tools or functions available to the agent. - configuration: Settings for prompt generation. - variables: Dynamic data for prompts. Functionality: - Manages contextual history. - Provides information for prompt/response cycles. Callbacks: Purpose: Enable advanced prompt management features. Features: - Contextual prompting. - Retrieval of information. - Generation response handling. - Persistence of data. ``` -------------------------------- ### Action View Runtime Configuration Options (APIDOC) Source: https://docs.activeagents.ai/docs/action-prompt/actions This section outlines the runtime options that can be applied to action views. These settings influence how the action's response is processed and delivered, including content type, view template selection, streaming behavior, and additional provider-specific options. ```APIDOC Runtime options: content_type: Specifies the type of content to be rendered (e.g., :text, :json, :html). view: Specifies the view template to be used for rendering the action's response. This can be a string representing the view file name or a symbol representing a predefined view. stream: If set to true, the response will be streamed to the user in real-time. This is useful for long-running actions or when you want to provide immediate feedback to the user. options: Additional options that can be passed to the generation provider, such as model parameters or generation settings. ``` -------------------------------- ### Define TravelAgent Actions (Ruby) Source: https://docs.activeagents.ai/docs/action-prompt/actions This Ruby class defines the `TravelAgent` with specific actions: `search`, `book`, and `confirm`. Each method illustrates how an agent can interact with external services (e.g., `Place`) and then use the `prompt` method to render different types of responses (text, JSON, HTML) using specified templates. ```ruby class TravelAgent < ActiveAgent::Agent def search Place.search(params[:location]) prompt(content_type: :text, template_name: 'search_results') end def book Place.book(hotel_id: params[:hotel_id], user_id: params[:user_id]) prompt(content_type: :json, template_name: 'booking_confirmation') end def confirm Place.confirm(params[:booking_id]) prompt(content_type: :html, template_name: 'confirmation_page') end end ``` -------------------------------- ### Initialize and Generate Agent Response (Ruby) Source: https://docs.activeagents.ai/docs/action-prompt/actions This Ruby snippet demonstrates how to initialize a `TravelAgent` with a specific message and then trigger the agent to generate a response. This process initiates the agent's ability to call actions based on the provided context. ```ruby parameterized_agent = TravelAgent.with(message: "I want to book a hotel in Paris") agent_text_prompt_context = parameterized_agent.text_prompt agent_text_prompt_context.generate_now ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.