### 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
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 %><%= @prompt.message %>