activeagent 0.2.3 → 0.2.4.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f659cf9684d31461a83a4ac64084506f2cff11ef3f4c8ea819025a05a0c9f65
4
- data.tar.gz: c48520b380b7774bfd910511424dc8cbfddba469c20d2cd74e6f7c2e508515b5
3
+ metadata.gz: 184241f5e4ba55a57a90127a92fe89893991e6b71afa1338f7f3ac4f321bc0b2
4
+ data.tar.gz: 268aee27278446080510e914eb826144c7d2e27b2e5707fc86be79c3264441c8
5
5
  SHA512:
6
- metadata.gz: 92f8faef24f551503ae65a9645b4ec86d5ceee547f6cc0438f2df5e114295fc7a325171bf34172d63d52a37b2486661cc99cd8d4048e7d6225c8220db4c73685
7
- data.tar.gz: 19f01fe1bdad7d6a216908a6088b3e66d766582f5ec71e76e8e02557f10c56e7fbbcdfbd9d6bdbffcb4f03fcb4c454ddb532e56ea3fea38a195da8c319a6c01b
6
+ metadata.gz: bb8cee4ce3dfc23379004df4b5ead15e5de241cad72ddf30f0fda09a70ebd5a07150a9de08581fc5e7b0de7d6cf02e44e097c26ebb054efcecd117989c7787a5
7
+ data.tar.gz: 59fefa71afbd284233b03ed80a4b86c4b9050f246dd6246d592d5ae5acdeda8d16be5bbc682dc0dbab235605052b878310a5d9ed421735eba20aebd9baf229b8
data/README.md CHANGED
@@ -1,43 +1,142 @@
1
- # Active Agent: README.md
2
-
3
1
  # Active Agent
4
2
 
5
- ## Agent
3
+ ## Install
6
4
 
7
- Create agents that take instructions, prompts, and perform actions
5
+ ### Gemfile
6
+ `gem 'activeagent', require: 'active_agent'`
8
7
 
9
- ### Generation Provider
8
+ ### CLI
9
+ `gem install activeagent`
10
10
 
11
- ```ruby
12
- class SupportAgent < ActiveAgent::Base
13
- generate_with :openai, model: ‘gpt-o3-mini’, temperature: 0.7
14
- end
11
+ ### Rails Generator
12
+ After installing the gem, run the Rails installation generator:
13
+
14
+ ```bash
15
+ $ rails generate active_agent:install
15
16
  ```
16
17
 
17
- `generate_with` sets the generation provider’s completion generation model and parameters.
18
+ This will create:
19
+ ```
20
+ create config/initializers/active_agent.rb
21
+ create config/active_agent.yml
22
+ create app/agents/application_agent.rb
23
+ create app/agents
24
+ ```
18
25
 
19
- `completion_response = SupportAgent.prompt(‘Help me!’).generate_now`
26
+ - An initializer that uses default configurations
27
+ ```ruby
28
+ # config/initializers/active_agent.rb
29
+ ActiveAgent.load_configuration(Rails.root.join('config', 'active_agent.yml'))
30
+ ```
31
+ - A YAML configuration file for provider settings, such as OpenAI and might include environment-specific configurations:
32
+ ```yaml
33
+ # config/active_agent.yml
34
+ development:
35
+ openai:
36
+ service: "OpenAI"
37
+ api_key: <%= Rails.application.credentials.dig(:openai, :api_key) %>
38
+ model: "gpt-3.5-turbo"
39
+ temperature: 0.7
40
+
41
+ production:
42
+ openai:
43
+ service: "OpenAI"
44
+ api_key: <%= Rails.application.credentials.dig(:openai, :api_key) %>
45
+ model: "gpt-3.5-turbo"
46
+ temperature: 0.7
20
47
 
21
- ```ruby
22
- class SupportAgent < ActiveAgent::Base
23
- generate_with :openai, model: ‘gpt-o3-mini’, temperature: 0.7
24
- embed_with :openai, model: ‘text-embedding-3-small’
25
- end
26
48
  ```
49
+ - A base application agent class
50
+ ```ruby
51
+ # app/agents/application_agent.rb
52
+ class ApplicationAgent < ActiveAgent::Base
53
+ layout 'agent'
54
+
55
+ def prompt
56
+ super { |format| format.text { render plain: params[:message] } }
57
+ end
58
+ ```
59
+ - The agents directory structure
27
60
 
28
- `embed_with` sets the generation provider’s embedding generation model and parameters.
61
+ ## Agent
62
+ Create agents that take instructions, prompts, and perform actions
29
63
 
30
- `embedding_response = SupportAgent.prompt(‘Help me!’).embed_now`
64
+ ### Rails Generator
65
+ To use the Rails Active Agent generator to create a new agent and the associated views for the requested action prompts:
31
66
 
32
- ### Instructions
67
+ ```bash
68
+ $ rails generate active_agent:agent travel search book plans
69
+ ```
70
+ This will create:
71
+ ```
72
+ create app/agents/travel_agent.rb
73
+ create app/views/agents/travel/search.text.erb
74
+ create app/views/agents/travel/book.text.erb
75
+ create app/views/agents/travel/plans.text.erb
76
+ ```
77
+
78
+ The generator creates:
79
+ - An agent class inheriting from ApplicationAgent
80
+ - Text template views for each action
81
+ - Action methods in the agent class for processing prompts
82
+
83
+ ### Agent Actions
84
+ ```ruby
85
+ class TravelAgent < ApplicationAgent
86
+ def search
87
+
88
+ prompt { |format| format.text { render plain: "Searching for travel options" } }
89
+ end
90
+
91
+ def book
92
+ prompt { |format| format.text { render plain: "Booking travel plans" } }
93
+ end
94
+
95
+ def plans
96
+ prompt { |format| format.text { render plain: "Making travel plans" } }
97
+ end
98
+ end
99
+ ```
100
+
101
+ ## Action Prompt
33
102
 
34
- Instructions are system prompts that predefine the agent’s intention.
103
+ Action Prompt provides the structured interface for composing AI interactions through messages, actions/tools, and conversation context. [Read more about Action Prompt](lib/active_agent/action_prompt/README.md)
35
104
 
36
- ### Prompt
105
+ ```ruby
106
+ agent.prompt(message: "Find hotels in Paris",
107
+ actions: [{name: "search", params: {query: "hotels paris"}}])
108
+ ```
109
+
110
+ The prompt interface manages:
111
+ - Message content and roles (system/user/assistant)
112
+ - Action/tool definitions and requests
113
+ - Headers and context tracking
114
+ - Content types and multipart handling
115
+
116
+ ### Generation Provider
117
+
118
+ Generation Provider defines how prompts are sent to AI services for completion and embedding generation. [Read more about Generation Providers](lib/active_agent/generation_provider/README.md)
37
119
 
38
- Action Prompt allows Active Agents to render plain text and HTML prompt templates. Calling generate on a prompt will send the prompt to the agent’s Generation Provider.
120
+ ```ruby
121
+ class VacationAgent < ActiveAgent::Base
122
+ # Try not to get too model-rous with the parameters!
123
+ generate_with :openai,
124
+ model: "gpt-4",
125
+ temperature: 0.7
126
+
127
+ # Embed yourself in the joy of vector search
128
+ embed_with :openai,
129
+ model: "text-embedding-ada-002"
130
+ end
131
+ ```
39
132
 
40
- `SupportAgent.prompt(“What does CRUD and REST mean?”)`
133
+ Providers handle:
134
+ - API client configuration
135
+ - Prompt/completion generation
136
+ - Stream processing
137
+ - Embedding generation
138
+ - Context management
139
+ - Error handling
41
140
 
42
141
  ### Queue Generation
43
142
 
@@ -49,7 +148,7 @@ Active Agents can define methods that are autoloaded as callable tools. These ac
49
148
 
50
149
  ## Actions
51
150
 
52
- ```
151
+ ```ruby
53
152
  def get_cat_image_base64
54
153
  uri = URI("https://cataas.com/cat")
55
154
  response = Net::HTTP.get_response(uri)
@@ -86,4 +185,4 @@ end
86
185
 
87
186
  response = SupportAgent.prompt(‘show me a picture of a cat’).generate_now
88
187
 
89
- response.message
188
+ response.message
@@ -1,44 +1,111 @@
1
1
  # Active Agent: Action Prompt
2
2
 
3
- ActionPrompt provides a structured way to create and manage prompts and tools for AI interactions. It includes several support classes to handle different aspects of prompt creation and management. The Base class implements an AbstractController to perform actions that render prompts..
3
+ 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.
4
4
 
5
- ## Main Components
5
+ Action Prompt manages the overall prompt structure including:
6
6
 
7
- Module - for including in your agent classes to provide prompt functionality.
8
- Base class - for creating and managing prompts in ActiveAgent.
9
- Tool class - for representing the tool object sent to the Agent's generation provider.
10
- Message - class for representing a single message within a prompt.
11
- Prompt - class for representing a the context of a prompt, including messages, actions, and other attributes.
7
+ - Messages list with system/user/assistant roles
8
+ - Action/tool definitions
9
+ - Headers and context tracking
10
+ - Content type and encoding
11
+ - Multipart message handling
12
12
 
13
- ### ActionPrompt::Base
14
-
15
- The base class is used to create and manage prompts in Active Agent. It provides the core functionality for creating and managing contexts woth prompts, tools, and messages.
16
-
17
- #### Core Methods
18
- `prompt` - Creates a new prompt object with the given attributes.
13
+ ```ruby
14
+ prompt = ActionPrompt::Prompt.new(
15
+ instructions: "System guidance",
16
+ message: "User input",
17
+ actions: [tool_definition, action_schema],
18
+ context: messages
19
+ )
20
+ ```
19
21
 
22
+ ## ActionPrompt::Message
20
23
 
21
- ### ActionPrompt::Tool
24
+ Represents individual messages with:
22
25
 
23
- ### ActionPrompt::Message
26
+ ### Content and Role
27
+ ```ruby
28
+ message = ActionPrompt::Message.new(
29
+ content: "Search for a hotel",
30
+ role: :user
31
+ )
32
+ ```
24
33
 
25
- Represents a single message within a prompt.
34
+ - Content stores the actual message text
35
+ - Role defines the message sender type (system/user/assistant/function/tool)
36
+ - Messages form interactions between roles in a Context
26
37
 
27
- ### ActionPrompt::Prompt
38
+ ### Action Requests and Responses
39
+ ```ruby
40
+ message = ActionPrompt::Message.new(
41
+ content: "Search for a hotel",
42
+ role: :tool,
43
+ requested_actions: [{name: "search", params: {query: "hotel"}}]
44
+ )
45
+ ```
46
+
47
+ - Tracks if message requests actions/tools
48
+ - Maintains list of requested_actions
49
+ - Action responses include function call results
50
+ - Handles tool execution state
51
+
52
+ ### Content Type and Encoding
53
+ - Default content_type is "text/plain"
54
+ - Supports multiple content types for rich messages
55
+ - Default charset is UTF-8
56
+ - Handles content encoding/decoding
57
+
58
+ ### Role Validation
59
+ - Enforces valid roles via VALID_ROLES constant
60
+ - Validates on message creation
61
+ - Raises ArgumentError for invalid roles
62
+ - Supported roles: system, assistant, user, tool, function
28
63
 
29
- Manages the overall structure of a prompt, including multiple messages, actions, and other attributes.
64
+ ```ruby
65
+ message = ActionPrompt::Message.new(
66
+ content: "Hello",
67
+ role: :user,
68
+ content_type: "text/plain",
69
+ charset: "UTF-8"
70
+ )
71
+ ```
30
72
 
31
73
  ### ActionPrompt::Action
32
74
 
33
- Represents an action that represents the tool object sent to the Agent's generation provider can be associated with a prompt or message.
75
+ Defines callable tools/functions:
34
76
 
35
- ## Usage
77
+ - Name and parameters schema
78
+ - Validation and type checking
79
+ - Response handling
80
+ - Action execution
36
81
 
37
- To use ActionPrompt in your agent, include the module in your agent class:
82
+ ## Usage with Base Agents
38
83
 
39
84
  ```ruby
40
- class MyAgent
41
- include ActiveAgent::ActionPrompt
42
-
43
- # Your agent code here
85
+ class MyAgent < ActiveAgent::Base
86
+ # Define available actions
87
+ def action_schemas
88
+ [
89
+ {name: "search", params: {query: :string}}
90
+ ]
91
+ end
92
+
93
+ # Handle action responses
94
+ def perform_action(action)
95
+ case action.name
96
+ when "search"
97
+ search_service.query(action.params[:query])
98
+ end
99
+ end
44
100
  end
101
+ ```
102
+
103
+ The Base agent integrates with ActionPrompt to:
104
+
105
+ 1. Create prompts with context
106
+ 2. Register available actions
107
+ 3. Process action requests
108
+ 4. Handle responses and update context
109
+ 5. Manage the conversation flow
110
+
111
+ See Base.rb for full agent integration details.
@@ -3,20 +3,27 @@ module ActiveAgent
3
3
  class Message
4
4
  VALID_ROLES = %w[system assistant user tool function].freeze
5
5
 
6
- attr_accessor :content, :role, :name, :action_requested, :requested_actions
6
+ attr_accessor :content, :role, :name, :action_requested, :requested_actions, :content_type, :charset
7
7
 
8
8
  def initialize(attributes = {})
9
+ @action_requested = @requested_actions.any?
10
+ @agent_class = attributes[:agent_class]
11
+ @charset = attributes[:charset] || "UTF-8"
9
12
  @content = attributes[:content] || ""
10
- @role = attributes[:role] || :user
13
+ @content_type = attributes[:content_type] || "text/plain"
11
14
  @name = attributes[:name]
12
- @agent_class = attributes[:agent_class]
15
+ @role = attributes[:role] || :user
13
16
  @requested_actions = attributes[:requested_actions] || []
14
- @action_requested = @requested_actions.any?
15
17
  validate_role
16
18
  end
17
19
 
18
20
  def to_h
19
- hash = {role: role, content: content}
21
+ hash = {
22
+ role: role,
23
+ content: content,
24
+ content_type: content_type,
25
+ charset: charset
26
+ }
20
27
  hash[:name] = name if name
21
28
  hash[:action_requested] = requested_actions.any?
22
29
  hash[:requested_actions] = requested_actions if requested_actions.any?
@@ -448,11 +448,15 @@ module ActiveAgent
448
448
  end
449
449
 
450
450
  def insert_part(container, response, charset)
451
- response[:charset] ||= charset
452
- prompt = ActiveAgent::ActionPrompt::Prompt.new(response)
451
+ prompt = ActiveAgent::ActionPrompt::Prompt.new
452
+ message = ActiveAgent::ActionPrompt::Message.new(
453
+ content: response[:body],
454
+ content_type: response[:content_type],
455
+ charset: charset
456
+ )
457
+ prompt.message = message
453
458
  container.add_part(prompt)
454
459
  end
455
-
456
460
  # This and #instrument_name is for caching instrument
457
461
  def instrument_payload(key)
458
462
  {
@@ -1,17 +1,72 @@
1
1
  # Active Agent: Generation Provider
2
2
 
3
- This README provides information about the base generation provider class and the generation provider module interfaces in the ActiveAgent library.
3
+ This README provides information about the generation provider interfaces and implementations in the ActiveAgent library.
4
4
 
5
5
  ## Main Components
6
6
 
7
- Base class - for creating and configuring generation providers.
8
- Module - for including in your agent classes to provide generation provider functionality.
7
+ - Base class - Abstract class for implementing generation providers
8
+ - OpenAI Provider - Reference implementation using OpenAI's API
9
+ - Response class - Standardized response wrapper
10
+ - Module - For including generation provider functionality in agents
9
11
 
10
- ### ActiveAgent::GenerationProvider::Base
12
+ ## Core Concepts
11
13
 
12
- The main class for creating and configuring generation providers. It provides the core functionality for creating and managing generation providers.
14
+ ### Base Provider Class
13
15
 
14
- #### Core Methods
16
+ The `ActiveAgent::GenerationProvider::Base` class defines the core interface that all providers must implement:
15
17
 
16
- ##### initialize(options = {})
17
- Creates a new generation provider object with the given options.
18
+ ```ruby
19
+ def generate(prompt)
20
+ raise NotImplementedError
21
+ end
22
+ ```
23
+
24
+ ### OpenAI Provider Implementation
25
+
26
+ The OpenAI provider shows how to implement a concrete generation provider:
27
+
28
+ - Handles authentication and client setup
29
+ - Implements prompt/completion generation
30
+ - Supports streaming responses
31
+ - Handles embeddings generation
32
+ - Manages context updates
33
+ - Processes tool/action calls
34
+
35
+ ### Provider Features
36
+
37
+ - Configuration - Providers accept config options for API keys, models, etc
38
+ - Streaming - Optional streaming support for realtime responses
39
+ - Action handling - Support for function/tool calling
40
+ - Error handling - Standardized error handling via GenerationProviderError
41
+ - Context management - Tracks conversation context and message history
42
+
43
+ ### Response Handling
44
+
45
+ The Response class wraps provider responses with a consistent interface:
46
+
47
+ ```ruby
48
+ Response.new(
49
+ prompt: prompt, # Original prompt
50
+ message: message, # Generated response
51
+ raw_response: raw # Provider-specific response
52
+ )
53
+ ```
54
+
55
+ ## Usage Example
56
+
57
+ ```ruby
58
+ # Configure provider
59
+ provider = ActiveAgent::GenerationProvider::OpenAIProvider.new(
60
+ "api_key" => ENV["OPENAI_API_KEY"],
61
+ "model" => "gpt-4"
62
+ )
63
+
64
+ # Generate completion
65
+ response = provider.generate(prompt)
66
+
67
+ # Access response
68
+ response.message.content # Generated text
69
+ response.raw_response # Raw provider response
70
+ ```
71
+
72
+ See the OpenAI provider implementation for a complete reference example.
@@ -1,3 +1,3 @@
1
1
  module ActiveAgent
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4.rc1"
3
3
  end
@@ -1,5 +1,9 @@
1
1
  <% module_namespacing do -%>
2
2
  class ApplicationAgent < ActiveAgent::Base
3
3
  layout 'agent'
4
+
5
+ def prompt
6
+ super { |format| format.text { render plain: params[:message] } }
7
+ end
4
8
  end
5
9
  <% end %>
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveAgent
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ def create_initializer
9
+ template "initializer.rb", "config/initializers/active_agent.rb"
10
+ end
11
+
12
+ def create_configuration
13
+ template "active_agent.yml", "config/active_agent.yml"
14
+ end
15
+
16
+ def create_application_agent
17
+ template "application_agent.rb", "app/agents/application_agent.rb"
18
+ end
19
+
20
+ def create_agents_directory
21
+ empty_directory "app/agents"
22
+ end
23
+
24
+ def show_readme
25
+ readme "README" if behavior == :invoke
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ default: &default
2
+ openai: &openai_default
3
+ access_token: <%= ENV['OPENAI_ACCESS_TOKEN'] %>
4
+ organization_id: <%= ENV['OPENAI_ORGANIZATION_ID'] %>
5
+ default_model: gpt-4
6
+ default_embedding_model: text-embedding-3-small
7
+ default_temperature: 0.7
8
+ request_timeout: 60
9
+
10
+ anthropic: &anthropic_default
11
+ access_token: <%= ENV['ANTHROPIC_ACCESS_TOKEN'] %>
12
+ default_model: claude-3-sonnet
13
+ default_temperature: 0.7
14
+ request_timeout: 60
15
+
16
+ development:
17
+ <<: *default
18
+
19
+ test:
20
+ <<: *default
21
+ test_mode: true
22
+ mock_responses: true
23
+
24
+ production:
25
+ <<: *default
26
+ openai:
27
+ <<: *openai_default
28
+ request_timeout: 120
29
+ anthropic:
30
+ <<: *anthropic_default
31
+ request_timeout: 120
32
+
33
+ staging:
34
+ <<: *production
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Configure ActiveAgent
4
+ ActiveAgent.configure do |config|
5
+ # Load configuration from config/active_agent.yml
6
+ config.load_configuration Rails.root.join("config", "active_agent.yml")
7
+
8
+ # Configure default provider settings
9
+ config.default_provider = :openai
10
+
11
+ # Configure default generation settings
12
+ config.default_generation_settings = {
13
+ temperature: 0.7,
14
+ top_p: 1.0,
15
+ frequency_penalty: 0.0,
16
+ presence_penalty: 0.0
17
+ }
18
+
19
+ # Configure default embedding settings
20
+ config.default_embedding_settings = {
21
+ dimensions: 1536
22
+ }
23
+
24
+ # Configure test mode - when true, will use mock responses
25
+ config.test_mode = Rails.env.test?
26
+
27
+ # Configure logging
28
+ config.logger = Rails.logger
29
+ config.log_level = Rails.env.production? ? :info : :debug
30
+
31
+ # Configure cache
32
+ config.cache = Rails.cache
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Bowen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-20 00:00:00.000000000 Z
11
+ date: 2025-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -130,8 +130,8 @@ dependencies:
130
130
  - - "<"
131
131
  - !ruby/object:Gem::Version
132
132
  version: '9.0'
133
- description: The AI Agent framework to make Rails the best framework for AI application
134
- development.
133
+ description: A simple way to perform long running LLM background jobs and streaming
134
+ responses
135
135
  email: jusbowen@gmail.com
136
136
  executables: []
137
137
  extensions: []
@@ -180,13 +180,13 @@ files:
180
180
  - lib/generators/active_agent/templates/agent_spec.rb.tt
181
181
  - lib/generators/active_agent/templates/agent_test.rb.tt
182
182
  - lib/generators/active_agent/templates/application_agent.rb.tt
183
- homepage:
183
+ - lib/generators/install_generator.rb
184
+ - lib/generators/templates/active_agent.yml
185
+ - lib/generators/templates/initializer.rb
186
+ homepage: https://rubygems.org/gems/activeagent
184
187
  licenses:
185
188
  - MIT
186
- metadata:
187
- homepage_uri: https://activeagents.ai
188
- source_code_uri: https://github.com/activeagents/activeagent
189
- bug_tracker_uri: https://github.com/activeagents/activeagent/issues
189
+ metadata: {}
190
190
  post_install_message:
191
191
  rdoc_options: []
192
192
  require_paths: