Skip to content

Commit 7af1b17

Browse files
committed
[WIP] Docs
1 parent f33e82f commit 7af1b17

39 files changed

+3053
-358
lines changed

docs/docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Messages are rendered by the Agent's actions when `prompt` is called. This `prom
4343
<FeatureCards :cards="$frontmatter.view" />
4444

4545
## Controller: Agents
46-
Agents are the core of the Active Agent framework and control the prompt and response cycle. Agents are controllers for AI-driven interactions, managing prompts, actions, and responses. Agents are responsible for managing context, handling user input, generating content, and interacting with generation providers.
46+
Agents are the core of the Active Agent framework and control the prompt and response cycle. Agents are controllers for AI-driven interactions, managing prompts, actions, and responses. Agents are responsible for managing context, handling user input, generating content, and interacting with providers.
4747

4848
<FeatureCards :cards="$frontmatter.controller" />
4949

docs/docs/action-prompt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Action Prompt is a core component of Active Agent that provides a structured way
66

77
Active Agent implements base methods that can be used by any agent that inherits from `ActiveAgent::Base`.
88

9-
The primary method is `Agent.prompt(...)` which provides a direct interface to create prompts with messages, and custom actions which use view templates for more complex formatting.
9+
For production applications, **custom actions** are the recommended approach for organizing agent behaviors. For testing and quick prototyping, `Agent.prompt(...)` provides a direct interface to create prompts with messages. Both actions and `Agent.prompt(...)` can work without view templates when passing messages directly.
1010

1111
Action Prompt leverages Action View templates to render messages and provides a consistent interface for generating content.

docs/docs/action-prompt/actions.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# 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.
33

44
## 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.
66

77
```ruby
88
# The prompt method is typically called within an action
99
class MyAgent < ApplicationAgent
1010
def my_action
1111
prompt(
1212
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)
1414
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
1616
instructions: { template: "instructions" }, # Optional instructions for the prompt generation
1717
actions: [], # Available actions for the agent to use
1818
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:
8888

8989
Example:
9090
```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:
92102
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
98107
}
99108
).search
100109
@@ -182,12 +191,11 @@ Available runtime options include:
182191
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.
183192
6. The agent updates the context with the action's result and prepares the response to be sent back to the user.
184193

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.
191199

192200
### Respond to User
193201
1. You provide the model with a prompt or conversation history, along with a set of tools.

docs/docs/action-prompt/messages.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Messages can be structured as a Message object or hash with the following attrib
99
- `content`: The content of the message, which can be plain text or formatted content.
1010
- `requested_actions`: An array of actions that the agent requested to be performed in response to the message. This is used to handle tool use requests from the agent.
1111

12-
<<< @/../test/agents/messages_examples_test.rb#messages_structure{ruby:line-numbers}
12+
<<< @/../test/agents/support_agent_test.rb#messages_structure{ruby:line-numbers}
1313

1414

1515
## Instructions as system messages to the agent
@@ -36,15 +36,15 @@ An `:assistant` message is used to represent the agent's response to the user. T
3636

3737
### Messages with Requested Actions
3838

39-
<<< @/../test/agents/messages_examples_test.rb#messages_with_actions{ruby:line-numbers}
39+
<<< @/../test/agents/support_agent_test.rb#messages_with_actions{ruby:line-numbers}
4040

4141
## The system responds to agent requested actions with :tool messages
4242
Agent performed actions result in `:tool` message. These messages are used to represent the response to a tool call made by the agent. This message is used to provide additional information about the tool call, such as the name of the tool and any arguments that were passed to the tool. The system can use this message to provide a response message containing the result of the tool call and can also include links or other interactive elements.
4343

44-
<<< @/../test/agents/messages_examples_test.rb#tool_messages{ruby:line-numbers}
44+
<<< @/../test/agents/support_agent_test.rb#tool_messages{ruby:line-numbers}
4545

4646
## Building Message Context
4747

4848
Messages form the conversation history that provides context for the agent. [Learn how messages flow through generation →](/docs/active-agent/generation)
4949

50-
<<< @/../test/agents/messages_examples_test.rb#message_context{ruby:line-numbers}
50+
<<< @/../test/agents/support_agent_test.rb#message_context{ruby:line-numbers}

docs/docs/action-prompt/prompts.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# Prompt
2-
3-
The Prompt is the container for runtime context messages and options passed to the generation provider.
4-
5-
Prompts are responsible for managing the contextual history and providing the necessary information to the generation provider for a meaningful prompt and response cycles.
6-
1+
# Prompts
2+
The Prompt is the container for runtime context messages and options passed to the provider.
73

4+
Prompts are responsible for managing the contextual history and providing the necessary information to the provider for a meaningful prompt and response cycles.
85
## Prompt Structure
96
The Prompt is structured to include the following components:
107
- **Messages**: An array of messages that represent the contextual information or conversational chat history. Each message includes content, role (user or assistant), and metadata.
@@ -13,9 +10,9 @@ The Prompt is structured to include the following components:
1310
- **Options**: Runtime configuration options that control the generation behavior (e.g., model, temperature, max_tokens). See [Runtime options](actions.md#runtime-options) for details.
1411

1512
## Example Prompt
16-
Prompts are built and rendered in the agent's action methods, typically using the `prompt` method. This is an example of creating a prompt by manually building the context; assigning `actions`, the prompt `message` and context `messages`.
13+
Prompts are built and rendered in the agent's action methods, typically using the `prompt` method. This is an example of creating a prompt by manually building the context; assigning the prompt `message` and context `messages`.
1714

18-
<<< @/../test/action_prompt/prompt_test.rb#support_agent_prompt_initialization{ruby:line-numbers} [support_agent.rb]
15+
<<< @/../test/agents/application_agent_test.rb#application_agent_loaded_context_message_generation{ruby:line-numbers}
1916

2017

2118
## Rendering Prompts
@@ -30,4 +27,4 @@ Prompts can be rendered using the `prompt` method inside an Agent's action metho
3027

3128
::: code-group
3229
<<< @/../test/agents/translation_agent_test.rb#translation_agent_render_translate_prompt{ruby} [test/agents/translation_agent_test.rb:6..8]
33-
:::
30+
:::

docs/docs/active-agent/generation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ Loading a context from an existing prompt context:
3030
## Prompt Generation Request-Response Cycle
3131
The prompt generation cycle is similar to the request-response cycle of Action Controller and is at the core of the Active Agent framework. It involves the following steps:
3232
1. **Prompt Context**: The Prompt object is created with the necessary context, including messages, actions, and parameters.
33-
2. **Generation Request**: The agent sends a request to the generation provider with the prompt context, including the messages and actions.
34-
3. **Generation Response**: The generation provider processes the request and returns a response, which is then passed back to the agent.
33+
2. **Generation Request**: The agent sends a request to the provider with the prompt context, including the messages and actions.
34+
3. **Generation Response**: The provider processes the request and returns a response, which is then passed back to the agent.
3535
4. **Response Handling**: The agent processes the response, which can be sent back to the user or used for further processing.
3636
5. **Action Execution**: If the response includes actions, the agent executes them and updates the context accordingly.
3737
6. **Updated Context**: The context is updated with the new messages, actions, and parameters, and the cycle continues. [Customize generation behavior with callbacks →](/docs/active-agent/callbacks)
3838
## Prompt Context
39-
Action Prompt renders prompt context objects that represent the contextual data and runtime parameters for the generation process. Prompt context objects contain messages, actions, and params that are passed in the request to the agent's generation provider. The context object is responsible for managing the contextual history and providing the necessary information for prompt and response cycles.
39+
Action Prompt renders prompt context objects that represent the contextual data and runtime parameters for the generation process. Prompt context objects contain messages, actions, and params that are passed in the request to the agent's provider. The context object is responsible for managing the contextual history and providing the necessary information for prompt and response cycles.

docs/docs/active-agent/structured-output.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ Handle JSON parsing errors gracefully:
110110

111111
Different AI providers have varying levels of structured output support:
112112

113-
- **[OpenAI](/docs/generation-providers/openai-provider#structured-output)** - Native JSON mode with strict schema validation
114-
- **[OpenRouter](/docs/generation-providers/open-router-provider#structured-output-support)** - Support through compatible models, ideal for multimodal tasks
115-
- **[Anthropic](/docs/generation-providers/anthropic-provider#structured-output)** - Instruction-based JSON generation
116-
- **[Ollama](/docs/generation-providers/ollama-provider#structured-output)** - Local model support with JSON mode
113+
- **[OpenAI](/docs/providers/openai-provider#structured-output)** - Native JSON mode with strict schema validation
114+
- **[OpenRouter](/docs/providers/open-router-provider#structured-output-support)** - Support through compatible models, ideal for multimodal tasks
115+
- **[Anthropic](/docs/providers/anthropic-provider#structured-output)** - Instruction-based JSON generation
116+
- **[Ollama](/docs/providers/ollama-provider#structured-output)** - Local model support with JSON mode
117117

118118
## Real-World Examples
119119

@@ -137,7 +137,7 @@ Leverage ActiveRecord/ActiveModel for single source of truth:
137137
```ruby
138138
class User < ApplicationRecord
139139
include ActiveAgent::SchemaGenerator
140-
140+
141141
validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP }
142142
validates :age, numericality: { greater_than: 18 }
143143
end
@@ -160,7 +160,7 @@ Always test structured output with real providers:
160160
test "extracts data with correct schema" do
161161
VCR.use_cassette("structured_extraction") do
162162
response = agent.extract_data.generate_now
163-
163+
164164
assert_equal "application/json", response.message.content_type
165165
assert response.message.content.is_a?(Hash)
166166
assert_valid_schema response.message.content, expected_schema
@@ -205,7 +205,7 @@ After:
205205
class ExtractedUser
206206
include ActiveModel::Model
207207
include ActiveAgent::SchemaGenerator
208-
208+
209209
attribute :name, :string
210210
attribute :age, :integer
211211
end
@@ -235,5 +235,5 @@ schema = ExtractedUser.to_json_schema(strict: true)
235235
## See Also
236236

237237
- [Data Extraction Agent](/docs/agents/data-extraction-agent) - Complete extraction examples
238-
- [OpenAI Structured Output](/docs/generation-providers/openai-provider#structured-output) - OpenAI implementation details
239-
- [OpenRouter Structured Output](/docs/generation-providers/open-router-provider#structured-output-support) - Multimodal extraction
238+
- [OpenAI Structured Output](/docs/providers/openai-provider#structured-output) - OpenAI implementation details
239+
- [OpenRouter Structured Output](/docs/providers/open-router-provider#structured-output-support) - Multimodal extraction

docs/docs/agents/data-extraction-agent.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Structured output requires a generation provider that supports JSON schemas. Cur
9898
- **OpenAI** - GPT-4o, GPT-4o-mini, GPT-3.5-turbo variants
9999
- **OpenRouter** - When using compatible models like OpenAI models through OpenRouter
100100

101-
See the [OpenRouter Provider documentation](/docs/generation-providers/open-router-provider#structured-output-support) for details on using structured output with multiple model providers.
101+
See the [OpenRouter Provider documentation](/docs/providers/open-router-provider#structured-output-support) for details on using structured output with multiple model providers.
102102
:::
103103

104104

@@ -164,7 +164,7 @@ Extract resume data with a predefined `resume_schema`:
164164

165165
For extracting data from receipts and invoices, you can use OpenRouter's multimodal capabilities combined with structured output. OpenRouter provides access to models that support both vision and structured output, making it ideal for document processing tasks.
166166

167-
See the [OpenRouter Receipt Extraction example](/docs/generation-providers/open-router-provider#receipt-data-extraction-with-structured-output) for a complete implementation that extracts:
167+
See the [OpenRouter Receipt Extraction example](/docs/providers/open-router-provider#receipt-data-extraction-with-structured-output) for a complete implementation that extracts:
168168
- Merchant information (name, address)
169169
- Line items with prices
170170
- Tax and total amounts
@@ -186,5 +186,5 @@ Choose your provider based on your specific needs:
186186
- **Anthropic**: Strong reasoning capabilities with Claude models
187187
- **Ollama**: Local model deployment for privacy-sensitive data
188188

189-
Learn more about configuring providers in the [Generation Provider Overview](/docs/framework/generation-provider).
190-
:::
189+
Learn more about configuring providers in the [Provider Overview](/docs/framework/provider).
190+
:::

0 commit comments

Comments
 (0)