activeagent 0.1.1 → 0.2.6.9

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active_agent/action_prompt/README.md +92 -25
  3. data/lib/active_agent/action_prompt/action.rb +13 -0
  4. data/lib/active_agent/action_prompt/base.rb +127 -0
  5. data/lib/active_agent/action_prompt/message.rb +18 -16
  6. data/lib/active_agent/action_prompt/prompt.rb +14 -15
  7. data/lib/active_agent/base.rb +96 -58
  8. data/lib/active_agent/callbacks.rb +13 -0
  9. data/lib/active_agent/generation.rb +3 -3
  10. data/lib/active_agent/generation_job.rb +1 -1
  11. data/lib/active_agent/generation_provider/README.md +63 -8
  12. data/lib/active_agent/generation_provider/anthropic_provider.rb +142 -0
  13. data/lib/active_agent/generation_provider/base.rb +7 -2
  14. data/lib/active_agent/generation_provider/open_ai_provider.rb +95 -24
  15. data/lib/active_agent/generation_provider.rb +1 -2
  16. data/lib/active_agent/operation.rb +3 -3
  17. data/lib/active_agent/queued_generation.rb +1 -1
  18. data/lib/active_agent/railtie.rb +9 -11
  19. data/lib/active_agent/service.rb +1 -1
  20. data/lib/active_agent/version.rb +1 -1
  21. data/lib/active_agent.rb +7 -3
  22. data/lib/activeagent.rb +1 -0
  23. data/lib/generators/active_agent/agent_generator.rb +22 -22
  24. data/lib/generators/active_agent/install_generator.rb +21 -0
  25. data/lib/generators/active_agent/templates/active_agent.yml +6 -0
  26. data/lib/generators/active_agent/templates/agent.rb.tt +1 -1
  27. data/lib/generators/active_agent/templates/agent.text.erb +1 -0
  28. data/lib/generators/active_agent/templates/application_agent.rb.tt +7 -0
  29. metadata +65 -20
  30. data/README.md +0 -153
  31. data/Rakefile +0 -3
data/README.md DELETED
@@ -1,153 +0,0 @@
1
- # ActiveAgent
2
-
3
- ActiveAgent is a Rails framework for creating and managing AI agents. It provides a structured way to interact with AI services through agents that can generate text, images, speech-to-text, and text-to-speech. It includes modules for defining prompts, actions, and rendering generative UI, as well as scaling with asynchronous jobs and streaming.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'active_agent'
11
- ```
12
-
13
- And then execute:
14
-
15
- ```sh
16
- bundle install
17
- ```
18
- ## Getting Started
19
-
20
- ## Usage
21
-
22
- ### Generating an Agent
23
- ```
24
- rails generate agent inventory search
25
- ```
26
-
27
- This will generate the following files:
28
- ```
29
- app/agents/application_agent.rb
30
- app/agents/inventory_agent.rb
31
- app/views/inventory_agent/search.text.erb
32
- app/views/inventory_agent/search.json.jbuilder
33
- ```
34
-
35
- ### Define Agents
36
-
37
- Agents are the core of ActiveAgent. An agent takes prompts and can perform actions to generate content. Agents are defined by a simple Ruby class that inherits from `ActiveAgent::Base` and are located in the `app/agents` directory.
38
-
39
- ```ruby
40
- #
41
-
42
- inventory_agent.rb
43
-
44
-
45
- class InventoryAgent < ActiveAgent::Base
46
- generate_with :openai, model: 'gpt-4o-mini', temperature: 0.5, instructions: :inventory_operations
47
-
48
- def search
49
- @items = Item.search(params[:query])
50
- end
51
-
52
- def inventory_operations
53
- @organization = Organization.find(params[:account_id])
54
- prompt
55
- end
56
- end
57
- ```
58
-
59
- ### Interact with AI Services
60
-
61
- ActiveAgent allows you to interact with various AI services to generate text, images, speech-to-text, and text-to-speech.
62
-
63
- ```ruby
64
- class SupportAgent < ActiveAgent::Base
65
- generate_with :openai, model: 'gpt-4o-mini', instructions: :instructions
66
-
67
- def perform(content, context)
68
- @content = content
69
- @context = context
70
- end
71
-
72
- def generate_message
73
- provider_instance.generate(self)
74
- end
75
-
76
- private
77
-
78
- def after_generate
79
- broadcast_message
80
- end
81
-
82
- def broadcast_message
83
- broadcast_append_later_to(
84
- broadcast_stream,
85
- target: broadcast_target,
86
- partial: 'support_agent/message',
87
- locals: { message: @message }
88
- )
89
- end
90
-
91
- def broadcast_stream
92
- "#{dom_id(@chat)}_messages"
93
- end
94
- end
95
- ```
96
-
97
- ### Render Generative UI
98
-
99
- ActiveAgent uses Action Prompt both for rendering `instructions` prompt views as well as rendering action views. Prompts are Action Views that provide instructions for the agent to generate content.
100
-
101
- ```erb
102
- <!--
103
-
104
- instructions.text.erb
105
-
106
- -->
107
- INSTRUCTIONS: You are an inventory manager for <%= @organization.name %>. You can search for inventory or reconcile inventory using <%= assigned_actions %>
108
- ```
109
-
110
- ### Scale with Asynchronous Jobs and Streaming
111
-
112
- ActiveAgent supports asynchronous job processing and streaming for scalable AI interactions.
113
-
114
- #### Asynchronous Jobs
115
-
116
- Use the `generate_later` method to enqueue a job for later processing.
117
-
118
- ```ruby
119
- InventoryAgent.with(query: query).search.generate_later
120
- ```
121
-
122
- #### Streaming
123
-
124
- Use the `stream_with` method to handle streaming responses.
125
-
126
- ```ruby
127
- class InventoryAgent < ActiveAgent::Base
128
- generate_with :openai, model: 'gpt-4o-mini', stream: :broadcast_results
129
-
130
- private
131
-
132
- def broadcast_results
133
- proc do |chunk, _bytesize|
134
- @message.content = @message.content + chunk
135
- broadcast_append_to(
136
- "#{dom_id(chat)}_messages",
137
- partial: "messages/message",
138
- locals: { message: @message, scroll_to: true },
139
- target: "#{dom_id(chat)}_messages"
140
- )
141
- end
142
- end
143
- end
144
- ```
145
-
146
- ## Contributing
147
-
148
- Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/active_agent.
149
-
150
- ## License
151
-
152
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
153
- ```
data/Rakefile DELETED
@@ -1,3 +0,0 @@
1
- require "bundler/setup"
2
-
3
- require "bundler/gem_tasks"