|
1 | 1 | # Actions |
2 | | -Active Agent uses Action View to render Message content for [Prompt](./prompts.md) context objects. |
| 2 | +Actions are the recommended way to organize agent behaviors in production applications. Active Agent can optionally use Action View to render Message content for [Prompt](./prompts.md) context objects when complex formatting is needed. |
3 | 3 |
|
4 | 4 | ## Prompt |
5 | | -The `prompt` method is used to render the action's content as a message in a prompt. The `prompt` method is similar to `mail` in Action Mailer or `render` in Action Controller, it allows you to specify the content type and view template for the action's response. |
| 5 | +The `prompt` method is used to render the action's content as a message in a prompt. The `prompt` method is similar to `mail` in Action Mailer or `render` in Action Controller. It can render view templates for complex formatting, or work without templates by passing message content directly. |
6 | 6 |
|
7 | 7 | ```ruby |
8 | 8 | # The prompt method is typically called within an action |
9 | 9 | class MyAgent < ApplicationAgent |
10 | 10 | def my_action |
11 | 11 | prompt( |
12 | 12 | content_type: :text, # or :json, :html, etc. |
13 | | - message: "Hello, world!", # The message content to be rendered |
| 13 | + message: "Hello, world!", # The message content (can be passed directly without a template) |
14 | 14 | messages: [], # Additional messages to include in the prompt context |
15 | | - template_name: "action_template", # The name of the view template to be used |
| 15 | + template_name: "action_template", # Optional: The name of the view template to use |
16 | 16 | instructions: { template: "instructions" }, # Optional instructions for the prompt generation |
17 | 17 | actions: [], # Available actions for the agent to use |
18 | 18 | output_schema: :schema_name # Optional schema for structured output |
@@ -88,13 +88,22 @@ When using the `with` method, it's important to understand the distinction: |
88 | 88 |
|
89 | 89 | Example: |
90 | 90 | ```ruby |
91 | | -# Regular parameters and runtime options |
| 91 | +**Explanation:** |
| 92 | + |
| 93 | +- **Action parameters** (e.g., `destination`, `user_id`) should be passed via the `:params` hash and accessed with `params[:key]` |
| 94 | +- **Runtime options** (like `model`, `temperature`, etc.) should be passed via the `:options` key to configure the provider |
| 95 | +- This separation provides clarity between business logic parameters and AI configuration |
| 96 | + |
| 97 | +```ruby |
| 98 | +# In the agent class: |
| 99 | +generate_with :openai, model: "gpt-4o-mini" |
| 100 | +
|
| 101 | +# When calling with runtime options: |
92 | 102 | TravelAgent.with( |
93 | | - destination: "Paris", # Regular parameter |
94 | | - user_id: 123, # Regular parameter |
95 | | - options: { # Runtime options |
96 | | - model: "gpt-4o", |
97 | | - temperature: 0.7 |
| 103 | + destination: "Paris", # Business logic params |
| 104 | + user_id: 123, # Business logic params |
| 105 | + options: { |
| 106 | + temperature: 0.9 # Provider configuration |
98 | 107 | } |
99 | 108 | ).search |
100 | 109 |
|
@@ -182,12 +191,11 @@ Available runtime options include: |
182 | 191 | 5. The action method returns a response, which can be a rendered view, JSON data, or any other content type specified in the `prompt` method. |
183 | 192 | 6. The agent updates the context with the action's result and prepares the response to be sent back to the user. |
184 | 193 |
|
185 | | -## How Agents handle responses |
186 | | -1. The agent receives a response from the generation provider, which includes the generated content and any actions that need to be performed. |
187 | | -2. The agent processes the response |
188 | | -3. If there are no `requested_actions` then response is sent back to the user. |
189 | | -4. If the response includes actions, then agent executes them and updates the context accordingly. |
190 | | -5. If the resulting context `requested_actions` includes `reiterate`, then context is updated with the new messages, actions, and parameters, and the cycle continues. |
| 194 | +## Tool Execution Flow |
| 195 | + |
| 196 | +When an agent calls an action: |
| 197 | + |
| 198 | +1. The agent receives a response from the provider, which includes the generated content and any actions that need to be performed. |
191 | 199 |
|
192 | 200 | ### Respond to User |
193 | 201 | 1. You provide the model with a prompt or conversation history, along with a set of tools. |
|
0 commit comments