activeagent 0.6.3 → 1.0.0.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 +4 -4
- data/CHANGELOG.md +210 -2
- data/README.md +15 -24
- data/lib/active_agent/base.rb +389 -39
- data/lib/active_agent/concerns/callbacks.rb +251 -0
- data/lib/active_agent/concerns/observers.rb +147 -0
- data/lib/active_agent/concerns/parameterized.rb +292 -0
- data/lib/active_agent/concerns/provider.rb +120 -0
- data/lib/active_agent/concerns/queueing.rb +36 -0
- data/lib/active_agent/concerns/rescue.rb +64 -0
- data/lib/active_agent/concerns/streaming.rb +282 -0
- data/lib/active_agent/concerns/tooling.rb +23 -0
- data/lib/active_agent/concerns/view.rb +150 -0
- data/lib/active_agent/configuration.rb +442 -20
- data/lib/active_agent/generation.rb +141 -47
- data/lib/active_agent/generation_provider/open_router/types.rb +505 -0
- data/lib/active_agent/generation_provider/xai_provider.rb +144 -0
- data/lib/active_agent/providers/_base_provider.rb +410 -0
- data/lib/active_agent/providers/anthropic/_types.rb +63 -0
- data/lib/active_agent/providers/anthropic/options.rb +53 -0
- data/lib/active_agent/providers/anthropic/request.rb +109 -0
- data/lib/active_agent/providers/anthropic/requests/_types.rb +190 -0
- data/lib/active_agent/providers/anthropic/requests/container_params.rb +19 -0
- data/lib/active_agent/providers/anthropic/requests/content/base.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/content/sources/base.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/context_management_config.rb +18 -0
- data/lib/active_agent/providers/anthropic/requests/messages/_types.rb +189 -0
- data/lib/active_agent/providers/anthropic/requests/messages/assistant.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/base.rb +63 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/_types.rb +143 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/base.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/document.rb +26 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/image.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/redacted_thinking.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/search_result.rb +27 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/_types.rb +171 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/base.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_base64.rb +25 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_file.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_text.rb +25 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_url.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_base64.rb +27 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_file.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_url.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/text.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/thinking.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/tool_result.rb +24 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/tool_use.rb +28 -0
- data/lib/active_agent/providers/anthropic/requests/messages/user.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/metadata.rb +18 -0
- data/lib/active_agent/providers/anthropic/requests/response_format.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/_types.rb +60 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/base.rb +20 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/disabled.rb +16 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/enabled.rb +20 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/_types.rb +78 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/any.rb +17 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/auto.rb +17 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/base.rb +20 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/none.rb +16 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/tool.rb +20 -0
- data/lib/active_agent/providers/anthropic_provider.rb +211 -0
- data/lib/active_agent/providers/common/messages/_types.rb +124 -0
- data/lib/active_agent/providers/common/messages/assistant.rb +57 -0
- data/lib/active_agent/providers/common/messages/base.rb +17 -0
- data/lib/active_agent/providers/common/messages/system.rb +20 -0
- data/lib/active_agent/providers/common/messages/tool.rb +21 -0
- data/lib/active_agent/providers/common/messages/user.rb +20 -0
- data/lib/active_agent/providers/common/model.rb +361 -0
- data/lib/active_agent/providers/common/response.rb +13 -0
- data/lib/active_agent/providers/common/responses/_types.rb +51 -0
- data/lib/active_agent/providers/common/responses/base.rb +151 -0
- data/lib/active_agent/providers/common/responses/embed.rb +33 -0
- data/lib/active_agent/providers/common/responses/format.rb +31 -0
- data/lib/active_agent/providers/common/responses/message.rb +3 -0
- data/lib/active_agent/providers/common/responses/prompt.rb +42 -0
- data/lib/active_agent/providers/concerns/exception_handler.rb +72 -0
- data/lib/active_agent/providers/concerns/previewable.rb +150 -0
- data/lib/active_agent/providers/log_subscriber.rb +360 -0
- data/lib/active_agent/providers/mock/_types.rb +77 -0
- data/lib/active_agent/providers/mock/embedding_request.rb +17 -0
- data/lib/active_agent/providers/mock/messages/_types.rb +103 -0
- data/lib/active_agent/providers/mock/messages/assistant.rb +26 -0
- data/lib/active_agent/providers/mock/messages/base.rb +63 -0
- data/lib/active_agent/providers/mock/messages/user.rb +18 -0
- data/lib/active_agent/providers/mock/options.rb +30 -0
- data/lib/active_agent/providers/mock/request.rb +38 -0
- data/lib/active_agent/providers/mock_provider.rb +311 -0
- data/lib/active_agent/providers/ollama/_types.rb +5 -0
- data/lib/active_agent/providers/ollama/chat/_types.rb +44 -0
- data/lib/active_agent/providers/ollama/chat/request.rb +70 -0
- data/lib/active_agent/providers/ollama/chat/requests/_types.rb +3 -0
- data/lib/active_agent/providers/ollama/chat/requests/messages/_types.rb +116 -0
- data/lib/active_agent/providers/ollama/chat/requests/messages/assistant.rb +19 -0
- data/lib/active_agent/providers/ollama/chat/requests/messages/user.rb +19 -0
- data/lib/active_agent/providers/ollama/embedding/_types.rb +44 -0
- data/lib/active_agent/providers/ollama/embedding/request.rb +77 -0
- data/lib/active_agent/providers/ollama/embedding/requests/_types.rb +83 -0
- data/lib/active_agent/providers/ollama/embedding/requests/options.rb +104 -0
- data/lib/active_agent/providers/ollama/options.rb +27 -0
- data/lib/active_agent/providers/ollama_provider.rb +95 -0
- data/lib/active_agent/providers/open_ai/_base.rb +58 -0
- data/lib/active_agent/providers/open_ai/_types.rb +5 -0
- data/lib/active_agent/providers/open_ai/chat/_types.rb +44 -0
- data/lib/active_agent/providers/open_ai/chat/request.rb +215 -0
- data/lib/active_agent/providers/open_ai/chat/requests/_types.rb +229 -0
- data/lib/active_agent/providers/open_ai/chat/requests/audio.rb +24 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/_types.rb +123 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/assistant.rb +42 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/base.rb +78 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/_types.rb +133 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/audio.rb +35 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/base.rb +24 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/file.rb +26 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/_types.rb +60 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/details.rb +41 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/image.rb +37 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/refusal.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/text.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/developer.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/function.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/system.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/tool.rb +26 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/user.rb +32 -0
- data/lib/active_agent/providers/open_ai/chat/requests/prediction.rb +46 -0
- data/lib/active_agent/providers/open_ai/chat/requests/response_format.rb +53 -0
- data/lib/active_agent/providers/open_ai/chat/requests/stream_options.rb +24 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tool_choice.rb +26 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/_types.rb +5 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/base.rb +22 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/custom_tool.rb +41 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/function_tool.rb +51 -0
- data/lib/active_agent/providers/open_ai/chat/requests/web_search_options.rb +45 -0
- data/lib/active_agent/providers/open_ai/chat_provider.rb +198 -0
- data/lib/active_agent/providers/open_ai/embedding/_types.rb +45 -0
- data/lib/active_agent/providers/open_ai/embedding/request.rb +85 -0
- data/lib/active_agent/providers/open_ai/embedding/requests/_types.rb +49 -0
- data/lib/active_agent/providers/open_ai/options.rb +74 -0
- data/lib/active_agent/providers/open_ai/responses/_types.rb +50 -0
- data/lib/active_agent/providers/open_ai/responses/request.rb +163 -0
- data/lib/active_agent/providers/open_ai/responses/requests/_types.rb +231 -0
- data/lib/active_agent/providers/open_ai/responses/requests/conversation.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/_types.rb +264 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/assistant_message.rb +22 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/base.rb +89 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/code_interpreter_tool_call.rb +30 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call_output.rb +33 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/_types.rb +207 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/base.rb +22 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_audio.rb +26 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_file.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_image.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_text.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call_output.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/developer_message.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/file_search_tool_call.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_call_output.rb +32 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_tool_call.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/image_gen_tool_call.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/input_message.rb +31 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/item_reference.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call.rb +26 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call_output.rb +33 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_request.rb +30 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_response.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_list_tools.rb +29 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_tool_call.rb +35 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/output_message.rb +35 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/reasoning.rb +33 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/system_message.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_call_base.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_message.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/user_message.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/web_search_tool_call.rb +24 -0
- data/lib/active_agent/providers/open_ai/responses/requests/prompt_reference.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/reasoning.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/stream_options.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/_types.rb +89 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/base.rb +22 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/json_object.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/json_schema.rb +48 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/plain.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text.rb +41 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tool_choice.rb +26 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/_types.rb +112 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/base.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/code_interpreter_tool.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/computer_tool.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/custom_tool.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/file_search_tool.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/function_tool.rb +29 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/image_generation_tool.rb +37 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/local_shell_tool.rb +21 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/mcp_tool.rb +41 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_preview_tool.rb +24 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_tool.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses_provider.rb +153 -0
- data/lib/active_agent/providers/open_ai/schema.yml +65937 -0
- data/lib/active_agent/providers/open_ai_provider.rb +97 -0
- data/lib/active_agent/providers/open_router/_types.rb +45 -0
- data/lib/active_agent/providers/open_router/options.rb +93 -0
- data/lib/active_agent/providers/open_router/request.rb +83 -0
- data/lib/active_agent/providers/open_router/requests/_types.rb +198 -0
- data/lib/active_agent/providers/open_router/requests/message.rb +1 -0
- data/lib/active_agent/providers/open_router/requests/messages/_types.rb +59 -0
- data/lib/active_agent/providers/open_router/requests/messages/assistant.rb +20 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/_types.rb +97 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/file.rb +27 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/files/_types.rb +61 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/files/details.rb +26 -0
- data/lib/active_agent/providers/open_router/requests/messages/user.rb +30 -0
- data/lib/active_agent/providers/open_router/requests/plugin.rb +25 -0
- data/lib/active_agent/providers/open_router/requests/plugins/_types.rb +46 -0
- data/lib/active_agent/providers/open_router/requests/plugins/pdf_config.rb +29 -0
- data/lib/active_agent/providers/open_router/requests/prediction.rb +17 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences/_types.rb +44 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences/max_price.rb +30 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences.rb +64 -0
- data/lib/active_agent/providers/open_router/requests/response_format.rb +49 -0
- data/lib/active_agent/providers/open_router_provider.rb +53 -0
- data/lib/active_agent/providers/openai_provider.rb +2 -0
- data/lib/active_agent/providers/openrouter_provider.rb +2 -0
- data/lib/active_agent/railtie.rb +8 -6
- data/lib/active_agent/schema_generator.rb +333 -166
- data/lib/active_agent/version.rb +1 -1
- data/lib/active_agent.rb +112 -36
- data/lib/generators/active_agent/agent/USAGE +78 -0
- data/lib/generators/active_agent/{agent_generator.rb → agent/agent_generator.rb} +14 -4
- data/lib/generators/active_agent/install/USAGE +25 -0
- data/lib/generators/active_agent/{install_generator.rb → install/install_generator.rb} +1 -19
- data/lib/generators/active_agent/templates/agent.rb.tt +7 -3
- data/lib/generators/active_agent/templates/application_agent.rb.tt +0 -2
- data/lib/generators/erb/agent_generator.rb +31 -16
- data/lib/generators/erb/templates/instructions.md.erb.tt +3 -0
- data/lib/generators/erb/templates/instructions.md.tt +3 -0
- data/lib/generators/erb/templates/instructions.text.tt +1 -0
- data/lib/generators/erb/templates/message.md.erb.tt +5 -0
- data/lib/generators/erb/templates/schema.json.tt +10 -0
- data/lib/generators/test_unit/agent_generator.rb +1 -1
- data/lib/generators/test_unit/templates/functional_test.rb.tt +4 -2
- metadata +320 -65
- data/lib/active_agent/action_prompt/action.rb +0 -13
- data/lib/active_agent/action_prompt/base.rb +0 -623
- data/lib/active_agent/action_prompt/message.rb +0 -126
- data/lib/active_agent/action_prompt/prompt.rb +0 -136
- data/lib/active_agent/action_prompt.rb +0 -19
- data/lib/active_agent/callbacks.rb +0 -33
- data/lib/active_agent/generation_provider/anthropic_provider.rb +0 -163
- data/lib/active_agent/generation_provider/base.rb +0 -55
- data/lib/active_agent/generation_provider/base_adapter.rb +0 -19
- data/lib/active_agent/generation_provider/error_handling.rb +0 -167
- data/lib/active_agent/generation_provider/log_subscriber.rb +0 -92
- data/lib/active_agent/generation_provider/message_formatting.rb +0 -107
- data/lib/active_agent/generation_provider/ollama_provider.rb +0 -66
- data/lib/active_agent/generation_provider/open_ai_provider.rb +0 -279
- data/lib/active_agent/generation_provider/open_router_provider.rb +0 -385
- data/lib/active_agent/generation_provider/parameter_builder.rb +0 -119
- data/lib/active_agent/generation_provider/response.rb +0 -75
- data/lib/active_agent/generation_provider/responses_adapter.rb +0 -44
- data/lib/active_agent/generation_provider/stream_processing.rb +0 -58
- data/lib/active_agent/generation_provider/tool_management.rb +0 -142
- data/lib/active_agent/generation_provider.rb +0 -67
- data/lib/active_agent/log_subscriber.rb +0 -44
- data/lib/active_agent/parameterized.rb +0 -75
- data/lib/active_agent/prompt_helper.rb +0 -19
- data/lib/active_agent/queued_generation.rb +0 -12
- data/lib/active_agent/rescuable.rb +0 -34
- data/lib/active_agent/sanitizers.rb +0 -40
- data/lib/active_agent/streaming.rb +0 -34
- data/lib/active_agent/test_case.rb +0 -125
- data/lib/generators/USAGE +0 -47
- data/lib/generators/active_agent/USAGE +0 -56
- data/lib/generators/erb/install_generator.rb +0 -44
- data/lib/generators/erb/templates/layout.html.erb.tt +0 -1
- data/lib/generators/erb/templates/layout.json.erb.tt +0 -1
- data/lib/generators/erb/templates/layout.text.erb.tt +0 -1
- data/lib/generators/erb/templates/view.html.erb.tt +0 -5
- data/lib/generators/erb/templates/view.json.erb.tt +0 -16
- /data/lib/active_agent/{preview.rb → concerns/preview.rb} +0 -0
- /data/lib/generators/erb/templates/{view.text.erb.tt → message.text.erb.tt} +0 -0
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module GenerationProvider
|
|
5
|
-
module ParameterBuilder
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
def prompt_parameters(overrides = {})
|
|
9
|
-
base_params = build_base_parameters
|
|
10
|
-
provider_params = build_provider_parameters
|
|
11
|
-
|
|
12
|
-
# Merge parameters with proper precedence:
|
|
13
|
-
# 1. Overrides (highest priority)
|
|
14
|
-
# 2. Prompt options
|
|
15
|
-
# 3. Provider-specific parameters
|
|
16
|
-
# 4. Base parameters (lowest priority)
|
|
17
|
-
base_params
|
|
18
|
-
.merge(provider_params)
|
|
19
|
-
.merge(extract_prompt_options)
|
|
20
|
-
.merge(overrides)
|
|
21
|
-
.compact
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
protected
|
|
25
|
-
|
|
26
|
-
def build_base_parameters
|
|
27
|
-
{
|
|
28
|
-
model: determine_model,
|
|
29
|
-
messages: provider_messages(@prompt.messages),
|
|
30
|
-
temperature: determine_temperature
|
|
31
|
-
}.tap do |params|
|
|
32
|
-
# Add optional parameters if present
|
|
33
|
-
params[:max_tokens] = determine_max_tokens if determine_max_tokens
|
|
34
|
-
params[:tools] = format_tools(@prompt.actions) if @prompt.actions.present?
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def build_provider_parameters
|
|
39
|
-
# Override in provider for specific parameters
|
|
40
|
-
# For example, Anthropic needs 'system' parameter instead of system message
|
|
41
|
-
{}
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def extract_prompt_options
|
|
45
|
-
# Extract relevant options from prompt
|
|
46
|
-
options = {}
|
|
47
|
-
|
|
48
|
-
# Common options that map directly
|
|
49
|
-
[ :stream, :top_p, :frequency_penalty, :presence_penalty, :seed, :stop, :user, :plugins ].each do |key|
|
|
50
|
-
options[key] = @prompt.options[key] if @prompt.options.key?(key)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Handle response format for structured output
|
|
54
|
-
if @prompt.output_schema.present?
|
|
55
|
-
options[:response_format] = build_response_format
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
options
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def determine_model
|
|
62
|
-
@prompt.options[:model] || @model_name || @config["model"]
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def determine_temperature
|
|
66
|
-
@prompt.options[:temperature] || @config["temperature"] || 0.7
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def determine_max_tokens
|
|
70
|
-
@prompt.options[:max_tokens] || @config["max_tokens"]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def build_response_format
|
|
74
|
-
# Default OpenAI-style response format
|
|
75
|
-
# Override in provider for different formats
|
|
76
|
-
{
|
|
77
|
-
type: "json_schema",
|
|
78
|
-
json_schema: @prompt.output_schema
|
|
79
|
-
}
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Embedding-specific parameters
|
|
83
|
-
def embeddings_parameters(input: nil, model: nil, **options)
|
|
84
|
-
{
|
|
85
|
-
model: model || determine_embedding_model,
|
|
86
|
-
input: input || format_embedding_input,
|
|
87
|
-
dimensions: options[:dimensions] || @config["embedding_dimensions"],
|
|
88
|
-
encoding_format: options[:encoding_format] || "float"
|
|
89
|
-
}.compact
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def determine_embedding_model
|
|
93
|
-
@prompt.options[:embedding_model] || @config["embedding_model"] || "text-embedding-3-small"
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def format_embedding_input
|
|
97
|
-
# Handle single or batch embedding inputs
|
|
98
|
-
if @prompt.message
|
|
99
|
-
@prompt.message.content
|
|
100
|
-
elsif @prompt.messages
|
|
101
|
-
@prompt.messages.map(&:content)
|
|
102
|
-
else
|
|
103
|
-
nil
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
module ClassMethods
|
|
108
|
-
# Class-level configuration for default parameters
|
|
109
|
-
def default_parameters(params = {})
|
|
110
|
-
@default_parameters = params
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def get_default_parameters
|
|
114
|
-
@default_parameters || {}
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module GenerationProvider
|
|
5
|
-
class Response
|
|
6
|
-
attr_reader :message, :prompt, :raw_response, :raw_request
|
|
7
|
-
attr_accessor :metadata
|
|
8
|
-
|
|
9
|
-
def initialize(prompt:, message: nil, raw_response: nil, raw_request: nil, metadata: nil)
|
|
10
|
-
@prompt = prompt
|
|
11
|
-
@message = message || prompt.message
|
|
12
|
-
@raw_response = raw_response
|
|
13
|
-
@raw_request = sanitize_request(raw_request)
|
|
14
|
-
@metadata = metadata || {}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Extract usage statistics from the raw response
|
|
18
|
-
def usage
|
|
19
|
-
return nil unless @raw_response
|
|
20
|
-
|
|
21
|
-
# Most providers store usage in the same format
|
|
22
|
-
if @raw_response.is_a?(Hash) && @raw_response["usage"]
|
|
23
|
-
@raw_response["usage"]
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Helper methods for common usage stats
|
|
28
|
-
def prompt_tokens
|
|
29
|
-
usage&.dig("prompt_tokens")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def completion_tokens
|
|
33
|
-
usage&.dig("completion_tokens")
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def total_tokens
|
|
37
|
-
usage&.dig("total_tokens")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
def sanitize_request(request)
|
|
43
|
-
return nil if request.nil?
|
|
44
|
-
return request unless request.is_a?(Hash)
|
|
45
|
-
|
|
46
|
-
# Deep clone the request to avoid modifying the original
|
|
47
|
-
sanitized = request.deep_dup
|
|
48
|
-
|
|
49
|
-
# Sanitize any string values in the request
|
|
50
|
-
sanitize_hash_values(sanitized)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def sanitize_hash_values(hash)
|
|
54
|
-
hash.each do |key, value|
|
|
55
|
-
case value
|
|
56
|
-
when String
|
|
57
|
-
# Use ActiveAgent's sanitize_credentials to replace sensitive data
|
|
58
|
-
hash[key] = ActiveAgent.sanitize_credentials(value)
|
|
59
|
-
when Hash
|
|
60
|
-
sanitize_hash_values(value)
|
|
61
|
-
when Array
|
|
62
|
-
value.each_with_index do |item, index|
|
|
63
|
-
if item.is_a?(String)
|
|
64
|
-
value[index] = ActiveAgent.sanitize_credentials(item)
|
|
65
|
-
elsif item.is_a?(Hash)
|
|
66
|
-
sanitize_hash_values(item)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
hash
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
require_relative "base_adapter"
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module GenerationProvider
|
|
5
|
-
class ResponsesAdapter < BaseAdapter
|
|
6
|
-
def initialize(prompt)
|
|
7
|
-
super(prompt)
|
|
8
|
-
@prompt = prompt
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def input
|
|
12
|
-
messages.map do |message|
|
|
13
|
-
if message.content.is_a?(Array)
|
|
14
|
-
{
|
|
15
|
-
role: message.role,
|
|
16
|
-
content: message.content.map do |content_part|
|
|
17
|
-
if content_part.is_a?(String)
|
|
18
|
-
{ type: "input_text", text: content_part }
|
|
19
|
-
elsif content_part.is_a?(ActiveAgent::ActionPrompt::Message) && content_part.content_type == "input_text"
|
|
20
|
-
{ type: "input_text", text: content_part.content }
|
|
21
|
-
elsif content_part.is_a?(ActiveAgent::ActionPrompt::Message) && content_part.content_type == "image_data"
|
|
22
|
-
{ type: "input_image", image_url: content_part.content }
|
|
23
|
-
elsif content_part.is_a?(ActiveAgent::ActionPrompt::Message) && content_part.content_type == "file_data"
|
|
24
|
-
{ type: "input_file", filename: content_part.metadata[:filename], file_data: content_part.content }
|
|
25
|
-
else
|
|
26
|
-
raise ArgumentError, "Unsupported content type in message"
|
|
27
|
-
end
|
|
28
|
-
end.compact
|
|
29
|
-
}
|
|
30
|
-
else
|
|
31
|
-
{
|
|
32
|
-
role: message.role,
|
|
33
|
-
content: message.content
|
|
34
|
-
}
|
|
35
|
-
end
|
|
36
|
-
end.compact
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def messages
|
|
40
|
-
prompt.messages
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module GenerationProvider
|
|
5
|
-
module StreamProcessing
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
included do
|
|
9
|
-
attr_accessor :stream_buffer, :stream_context
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def provider_stream
|
|
13
|
-
agent_stream = prompt.options[:stream]
|
|
14
|
-
message = initialize_stream_message
|
|
15
|
-
|
|
16
|
-
@response = ActiveAgent::GenerationProvider::Response.new(prompt:, message:)
|
|
17
|
-
|
|
18
|
-
proc do |chunk|
|
|
19
|
-
process_stream_chunk(chunk, message, agent_stream)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
protected
|
|
24
|
-
|
|
25
|
-
def initialize_stream_message
|
|
26
|
-
ActiveAgent::ActionPrompt::Message.new(content: "", role: :assistant)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def process_stream_chunk(chunk, message, agent_stream)
|
|
30
|
-
# Default implementation - must be overridden in provider
|
|
31
|
-
raise NotImplementedError, "Providers must implement process_stream_chunk"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def handle_stream_delta(delta, message, agent_stream)
|
|
35
|
-
# Common delta handling logic
|
|
36
|
-
new_content = extract_content_from_delta(delta)
|
|
37
|
-
if new_content && !new_content.blank?
|
|
38
|
-
message.content += new_content
|
|
39
|
-
agent_stream&.call(message, new_content, false, prompt.action_name)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def extract_content_from_delta(delta)
|
|
44
|
-
# Default extraction - override if needed
|
|
45
|
-
delta if delta.is_a?(String)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def handle_tool_stream_chunk(chunk, message, agent_stream)
|
|
49
|
-
# Handle tool calls in streaming
|
|
50
|
-
# Override in provider for specific implementation
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def finalize_stream(message, agent_stream)
|
|
54
|
-
agent_stream&.call(message, nil, true, prompt.action_name)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module GenerationProvider
|
|
5
|
-
module ToolManagement
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
def format_tools(tools)
|
|
9
|
-
return nil if tools.blank?
|
|
10
|
-
|
|
11
|
-
tools.map do |tool|
|
|
12
|
-
format_single_tool(tool)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def handle_actions(tool_calls)
|
|
17
|
-
return [] if tool_calls.nil? || tool_calls.empty?
|
|
18
|
-
|
|
19
|
-
tool_calls.map do |tool_call|
|
|
20
|
-
parse_tool_call(tool_call)
|
|
21
|
-
end.compact
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
protected
|
|
25
|
-
|
|
26
|
-
def format_single_tool(tool)
|
|
27
|
-
# Default implementation for OpenAI-style tools
|
|
28
|
-
if tool["function"] || tool[:function]
|
|
29
|
-
# Tool already has the correct structure
|
|
30
|
-
tool
|
|
31
|
-
else
|
|
32
|
-
# Legacy format - wrap in function structure
|
|
33
|
-
wrap_tool_in_function(tool)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def wrap_tool_in_function(tool)
|
|
38
|
-
{
|
|
39
|
-
type: "function",
|
|
40
|
-
function: {
|
|
41
|
-
name: tool["name"] || tool[:name],
|
|
42
|
-
description: tool["description"] || tool[:description],
|
|
43
|
-
parameters: tool["parameters"] || tool[:parameters]
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def parse_tool_call(tool_call)
|
|
49
|
-
# Skip if no function information
|
|
50
|
-
return nil if tool_call.nil?
|
|
51
|
-
|
|
52
|
-
# Extract tool information based on provider format
|
|
53
|
-
tool_id = extract_tool_id(tool_call)
|
|
54
|
-
tool_name = extract_tool_name(tool_call)
|
|
55
|
-
tool_params = extract_tool_params(tool_call)
|
|
56
|
-
|
|
57
|
-
# Skip if no name found
|
|
58
|
-
return nil if tool_name.blank?
|
|
59
|
-
|
|
60
|
-
ActiveAgent::ActionPrompt::Action.new(
|
|
61
|
-
id: tool_id,
|
|
62
|
-
name: tool_name,
|
|
63
|
-
params: tool_params
|
|
64
|
-
)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def extract_tool_id(tool_call)
|
|
68
|
-
tool_call["id"] || tool_call[:id]
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def extract_tool_name(tool_call)
|
|
72
|
-
# Try different paths for tool name
|
|
73
|
-
tool_call.dig("function", "name") ||
|
|
74
|
-
tool_call.dig(:function, :name) ||
|
|
75
|
-
tool_call["name"] ||
|
|
76
|
-
tool_call[:name]
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def extract_tool_params(tool_call)
|
|
80
|
-
# Try different paths for tool parameters/arguments
|
|
81
|
-
args = tool_call.dig("function", "arguments") ||
|
|
82
|
-
tool_call.dig(:function, :arguments) ||
|
|
83
|
-
tool_call["arguments"] ||
|
|
84
|
-
tool_call[:arguments] ||
|
|
85
|
-
tool_call["input"] ||
|
|
86
|
-
tool_call[:input]
|
|
87
|
-
|
|
88
|
-
return nil if args.blank?
|
|
89
|
-
|
|
90
|
-
# Parse JSON string if needed
|
|
91
|
-
if args.is_a?(String)
|
|
92
|
-
begin
|
|
93
|
-
JSON.parse(args, symbolize_names: true)
|
|
94
|
-
rescue JSON::ParserError
|
|
95
|
-
nil
|
|
96
|
-
end
|
|
97
|
-
else
|
|
98
|
-
args
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# Provider-specific tool format methods
|
|
103
|
-
# Override these in specific providers
|
|
104
|
-
|
|
105
|
-
def format_tools_for_anthropic(tools)
|
|
106
|
-
# Anthropic-specific tool format
|
|
107
|
-
tools.map do |tool|
|
|
108
|
-
{
|
|
109
|
-
name: extract_tool_name_from_schema(tool),
|
|
110
|
-
description: extract_tool_description_from_schema(tool),
|
|
111
|
-
input_schema: extract_tool_parameters_from_schema(tool)
|
|
112
|
-
}
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def format_tools_for_openai(tools)
|
|
117
|
-
# OpenAI-specific tool format (default)
|
|
118
|
-
format_tools(tools)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
private
|
|
122
|
-
|
|
123
|
-
def extract_tool_name_from_schema(tool)
|
|
124
|
-
tool["name"] || tool[:name] ||
|
|
125
|
-
tool.dig("function", "name") || tool.dig(:function, "name") ||
|
|
126
|
-
tool.dig("function", :name) || tool.dig(:function, :name)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def extract_tool_description_from_schema(tool)
|
|
130
|
-
tool["description"] || tool[:description] ||
|
|
131
|
-
tool.dig("function", "description") || tool.dig(:function, "description") ||
|
|
132
|
-
tool.dig("function", :description) || tool.dig(:function, :description)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def extract_tool_parameters_from_schema(tool)
|
|
136
|
-
tool["parameters"] || tool[:parameters] ||
|
|
137
|
-
tool.dig("function", "parameters") || tool.dig(:function, "parameters") ||
|
|
138
|
-
tool.dig("function", :parameters) || tool.dig(:function, :parameters)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module GenerationProvider
|
|
5
|
-
extend ActiveSupport::Concern
|
|
6
|
-
|
|
7
|
-
included do
|
|
8
|
-
class_attribute :_generation_provider_name, instance_accessor: false, instance_predicate: false
|
|
9
|
-
class_attribute :_generation_provider, instance_accessor: false, instance_predicate: false
|
|
10
|
-
|
|
11
|
-
delegate :generation_provider, to: :class
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
module ClassMethods
|
|
15
|
-
def configuration(name_or_provider, **options)
|
|
16
|
-
config = ActiveAgent.config[name_or_provider.to_s] || ActiveAgent.config.dig(ENV["RAILS_ENV"], name_or_provider.to_s) || {}
|
|
17
|
-
config = { "service" => "OpenAI" } if config.empty? && name_or_provider == :openai
|
|
18
|
-
config.merge!(options)
|
|
19
|
-
raise "Failed to load provider #{name_or_provider}: configuration not found for provider" if config["service"].nil?
|
|
20
|
-
configure_provider(config)
|
|
21
|
-
rescue LoadError => e
|
|
22
|
-
raise RuntimeError, "Failed to load provider #{name_or_provider}: #{e.message}"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def configure_provider(config)
|
|
26
|
-
service_name = config["service"]
|
|
27
|
-
require "active_agent/generation_provider/#{service_name.underscore}_provider"
|
|
28
|
-
|
|
29
|
-
ActiveAgent::GenerationProvider.const_get("#{service_name.camelize}Provider").new(config)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def generation_provider
|
|
33
|
-
self.generation_provider = :openai if _generation_provider.nil?
|
|
34
|
-
_generation_provider
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def generation_provider_name
|
|
38
|
-
self.generation_provider = :openai if _generation_provider_name.nil?
|
|
39
|
-
_generation_provider_name
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def generation_provider=(name_or_provider)
|
|
43
|
-
case name_or_provider
|
|
44
|
-
when Symbol, String
|
|
45
|
-
provider = configuration(name_or_provider)
|
|
46
|
-
assign_provider(name_or_provider.to_s, provider)
|
|
47
|
-
when OpenAI::Client
|
|
48
|
-
name = :openai
|
|
49
|
-
assign_provider(name, name_or_provider)
|
|
50
|
-
else
|
|
51
|
-
raise ArgumentError
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
def assign_provider(provider_name, generation_provider)
|
|
58
|
-
self._generation_provider_name = provider_name
|
|
59
|
-
self._generation_provider = generation_provider
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def generation_provider
|
|
64
|
-
self.class.generation_provider
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# # frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# require "active_support/log_subscriber"
|
|
4
|
-
|
|
5
|
-
# module ActiveAgent
|
|
6
|
-
# # = Active Agent \LogSubscriber
|
|
7
|
-
# #
|
|
8
|
-
# # Implements the ActiveSupport::LogSubscriber for logging notifications when
|
|
9
|
-
# # prompt is generated.
|
|
10
|
-
# class LogSubscriber < ActiveSupport::LogSubscriber
|
|
11
|
-
# # A prompt was generated.
|
|
12
|
-
# def deliver(event)
|
|
13
|
-
# info do
|
|
14
|
-
# if exception = event.payload[:exception_object]
|
|
15
|
-
# "Failed delivery of prompt #{event.payload[:message_id]} error_class=#{exception.class} error_message=#{exception.message.inspect}"
|
|
16
|
-
# elsif event.payload[:perform_deliveries]
|
|
17
|
-
# "Generated response for prompt #{event.payload[:message_id]} (#{event.duration.round(1)}ms)"
|
|
18
|
-
# else
|
|
19
|
-
# "Skipped generation of prompt #{event.payload[:message_id]} as `perform_generation` is false"
|
|
20
|
-
# end
|
|
21
|
-
# end
|
|
22
|
-
|
|
23
|
-
# debug { event.payload[:prompt] }
|
|
24
|
-
# end
|
|
25
|
-
# subscribe_log_level :deliver, :debug
|
|
26
|
-
|
|
27
|
-
# # A prompt was rendered.
|
|
28
|
-
# def process(event)
|
|
29
|
-
# debug do
|
|
30
|
-
# agent = event.payload[:agent]
|
|
31
|
-
# action = event.payload[:action]
|
|
32
|
-
# "#{agent}##{action}: processed outbound prompt in #{event.duration.round(1)}ms"
|
|
33
|
-
# end
|
|
34
|
-
# end
|
|
35
|
-
# subscribe_log_level :process, :debug
|
|
36
|
-
|
|
37
|
-
# # Use the logger configured for ActiveAgent::Base.
|
|
38
|
-
# def logger
|
|
39
|
-
# ActiveAgent::Base.logger
|
|
40
|
-
# end
|
|
41
|
-
# end
|
|
42
|
-
# end
|
|
43
|
-
|
|
44
|
-
# ActiveAgent::LogSubscriber.attach_to :active_agent
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module Parameterized
|
|
5
|
-
extend ActiveSupport::Concern
|
|
6
|
-
|
|
7
|
-
included do
|
|
8
|
-
attr_writer :params
|
|
9
|
-
|
|
10
|
-
def params
|
|
11
|
-
@params ||= {}
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
module ClassMethods
|
|
16
|
-
def with(params = {})
|
|
17
|
-
# Separate runtime options from regular params
|
|
18
|
-
# runtime_options = params.extract!(:model, :temperature, :max_tokens, :stream, :top_p,
|
|
19
|
-
# :frequency_penalty, :presence_penalty, :response_format,
|
|
20
|
-
# :seed, :stop, :tools_choice, :user)
|
|
21
|
-
|
|
22
|
-
# # Pass runtime options as :options parameter
|
|
23
|
-
# params[:options] = runtime_options if runtime_options.any?
|
|
24
|
-
|
|
25
|
-
ActiveAgent::Parameterized::Agent.new(self, params)
|
|
26
|
-
end
|
|
27
|
-
alias_method :prompt_with, :with
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class Agent
|
|
31
|
-
def initialize(agent, params)
|
|
32
|
-
@agent = agent
|
|
33
|
-
@params = params
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def method_missing(method_name, ...)
|
|
37
|
-
if @agent.public_instance_methods.include?(method_name)
|
|
38
|
-
ActiveAgent::Parameterized::Generation.new(@agent, method_name, @params, ...)
|
|
39
|
-
else
|
|
40
|
-
super
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def respond_to_missing?(method, include_all = false)
|
|
45
|
-
@agent.respond_to?(method, include_all)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
class Generation < ActiveAgent::Generation
|
|
50
|
-
def initialize(agent_class, action, params, ...)
|
|
51
|
-
super(agent_class, action, ...)
|
|
52
|
-
@params = params
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
def processed_agent
|
|
58
|
-
@processed_agent ||= @agent_class.new.tap do |agent|
|
|
59
|
-
agent.params = @params
|
|
60
|
-
agent.process @action, *@args
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def enqueue_generation(generation_method, options = {})
|
|
65
|
-
if processed?
|
|
66
|
-
super
|
|
67
|
-
else
|
|
68
|
-
@agent_class.generation_job.set(options).perform_later(
|
|
69
|
-
@agent_class.name, @action.to_s, generation_method.to_s, params: @params, args: @args
|
|
70
|
-
)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
# = Active Agent's Action Prompt \PromptHelper
|
|
5
|
-
#
|
|
6
|
-
# Provides helper methods for ActiveAgent::Base that can be used for easily
|
|
7
|
-
# formatting prompts, accessing agent or prompt instances.
|
|
8
|
-
module PromptHelper
|
|
9
|
-
# Access the agent instance.
|
|
10
|
-
def agent
|
|
11
|
-
@_controller
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Access the prompt instance.
|
|
15
|
-
def context
|
|
16
|
-
@_context
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module QueuedGeneration
|
|
5
|
-
extend ActiveSupport::Concern
|
|
6
|
-
|
|
7
|
-
included do
|
|
8
|
-
class_attribute :generation_job, default: ::ActiveAgent::GenerationJob
|
|
9
|
-
class_attribute :generate_later_queue_name, default: :agents
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent # :nodoc:
|
|
4
|
-
# = Active Agent \Rescuable
|
|
5
|
-
#
|
|
6
|
-
# Provides
|
|
7
|
-
# {rescue_from}[rdoc-ref:ActiveSupport::Rescuable::ClassMethods#rescue_from]
|
|
8
|
-
# for agents. Wraps agent action processing, generation job processing, and prompt
|
|
9
|
-
# generation to handle configured errors.
|
|
10
|
-
module Rescuable
|
|
11
|
-
extend ActiveSupport::Concern
|
|
12
|
-
include ActiveSupport::Rescuable
|
|
13
|
-
|
|
14
|
-
class_methods do
|
|
15
|
-
def handle_exception(exception) # :nodoc:
|
|
16
|
-
rescue_with_handler(exception) || raise(exception)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def handle_exceptions # :nodoc:
|
|
21
|
-
yield
|
|
22
|
-
rescue => exception
|
|
23
|
-
rescue_with_handler(exception) || raise
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
def process(...)
|
|
29
|
-
handle_exceptions do
|
|
30
|
-
super
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|