legate 0.1.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +345 -0
- data/bin/legate +13 -0
- data/examples/00_quickstart.rb +51 -0
- data/examples/01_simple_agent.rb +105 -0
- data/examples/02_multi_tool_agent.rb +140 -0
- data/examples/03_custom_tool.rb +93 -0
- data/examples/04_agent_instructions.rb +84 -0
- data/examples/05_state_and_sessions.rb +91 -0
- data/examples/06_callbacks.rb +186 -0
- data/examples/07_async_jobs.rb +112 -0
- data/examples/08_loop_agent.rb +197 -0
- data/examples/09_sequential_workflow.rb +40 -0
- data/examples/10_parallel_workflow.rb +34 -0
- data/examples/11_agent_delegation.rb +24 -0
- data/examples/12_http_client_tool.rb +156 -0
- data/examples/13_authentication.rb +220 -0
- data/examples/14_mcp_client.rb +154 -0
- data/examples/15_mcp_server.rb +79 -0
- data/examples/16_webhooks.rb +91 -0
- data/examples/README_sequential_agents.md +164 -0
- data/examples/advanced/auth/cookie_auth_tool.rb +146 -0
- data/examples/advanced/auth/custom_auth_flows_example.rb +626 -0
- data/examples/advanced/auth/excon_middleware.rb +317 -0
- data/examples/advanced/auth/excon_middleware_auth.rb +399 -0
- data/examples/advanced/auth/fiber_auth_example.rb +281 -0
- data/examples/advanced/auth/fiber_oidc_example.rb +403 -0
- data/examples/advanced/auth/httpbin_bearer_tool.rb +159 -0
- data/examples/advanced/auth/oauth2_auth.rb +419 -0
- data/examples/advanced/auth/oidc_auth.rb +514 -0
- data/examples/advanced/auth/openweather_api.rb +251 -0
- data/examples/advanced/auth/openweather_tool.rb +153 -0
- data/examples/advanced/auth/query_param_middleware_test.rb +138 -0
- data/examples/advanced/auth/service_account.rb +135 -0
- data/examples/advanced/auth/test_with_httpbin.rb +202 -0
- data/examples/advanced/auth/token_lifecycle_example.rb +428 -0
- data/examples/advanced/callback_monitoring.rb +679 -0
- data/examples/advanced/mas/fixed_delegation_example.rb +191 -0
- data/examples/advanced/mas/loop_workflow.rb +28 -0
- data/examples/advanced/mas/mock_planner.rb +77 -0
- data/examples/advanced/mas/proper_delegation_example.rb +276 -0
- data/examples/advanced/mcp/legate_mcp_server_resource_example.rb +182 -0
- data/examples/advanced/mcp/mcp_resource_server_example.rb +309 -0
- data/examples/advanced/mcp/mcp_server_async.rb +76 -0
- data/examples/advanced/mcp/mcp_server_async_tools.rb +122 -0
- data/examples/advanced/mcp/mcp_server_legate_agent.rb +95 -0
- data/examples/advanced/mcp/mcp_server_rack.rb +89 -0
- data/examples/advanced/random_calculator.rb +104 -0
- data/examples/advanced/sleep_agent.rb +153 -0
- data/examples/advanced/webhooks/webhook_e2e_runner.rb +110 -0
- data/examples/advanced/webhooks/webhook_receiver_agent.rb +58 -0
- data/examples/advanced/workflows/task_refinement_loop_agent.rb +278 -0
- data/examples/advanced/workflows/travel_planner_auto_sequential.rb +444 -0
- data/examples/advanced/workflows/travel_planner_parallel.rb +656 -0
- data/examples/advanced/workflows/travel_planner_sequential.rb +512 -0
- data/examples/tools/oauth2_example.rb +136 -0
- data/examples/tools/sleepy_tool.rb +42 -0
- data/lib/legate/activity_log.rb +71 -0
- data/lib/legate/agent.rb +959 -0
- data/lib/legate/agent_code_generator.rb +185 -0
- data/lib/legate/agent_definition.rb +812 -0
- data/lib/legate/agentic/decision.rb +49 -0
- data/lib/legate/agentic/loop.rb +134 -0
- data/lib/legate/agentic.rb +5 -0
- data/lib/legate/agents/loop_agent.rb +248 -0
- data/lib/legate/agents/parallel_agent.rb +163 -0
- data/lib/legate/agents/sequential_agent.rb +190 -0
- data/lib/legate/agents.rb +14 -0
- data/lib/legate/auth/config.rb +148 -0
- data/lib/legate/auth/coordinator.rb +218 -0
- data/lib/legate/auth/coordinators/oauth2_coordinator.rb +99 -0
- data/lib/legate/auth/coordinators/oidc_coordinator.rb +68 -0
- data/lib/legate/auth/coordinators/service_account_coordinator.rb +122 -0
- data/lib/legate/auth/credential.rb +157 -0
- data/lib/legate/auth/encryption.rb +108 -0
- data/lib/legate/auth/error.rb +94 -0
- data/lib/legate/auth/exchanged_credential.rb +180 -0
- data/lib/legate/auth/excon_middleware.rb +285 -0
- data/lib/legate/auth/http_client_utils.rb +364 -0
- data/lib/legate/auth/manager.rb +531 -0
- data/lib/legate/auth/manager_store.rb +394 -0
- data/lib/legate/auth/middleware_factory.rb +290 -0
- data/lib/legate/auth/runner.rb +279 -0
- data/lib/legate/auth/scheme.rb +125 -0
- data/lib/legate/auth/schemes/api_key.rb +212 -0
- data/lib/legate/auth/schemes/google_service_account.rb +108 -0
- data/lib/legate/auth/schemes/http_bearer.rb +98 -0
- data/lib/legate/auth/schemes/oauth2.rb +396 -0
- data/lib/legate/auth/schemes/openid_connect.rb +346 -0
- data/lib/legate/auth/schemes/service_account.rb +388 -0
- data/lib/legate/auth/schemes.rb +40 -0
- data/lib/legate/auth/token_manager.rb +362 -0
- data/lib/legate/auth/token_store.rb +86 -0
- data/lib/legate/auth/tool_context_extension.rb +97 -0
- data/lib/legate/auth/tool_integration.rb +188 -0
- data/lib/legate/auth/url_guard.rb +81 -0
- data/lib/legate/auth.rb +453 -0
- data/lib/legate/callbacks/callback_context.rb +71 -0
- data/lib/legate/cli/agent_commands.rb +950 -0
- data/lib/legate/cli/auth_commands.rb +520 -0
- data/lib/legate/cli/base_command.rb +24 -0
- data/lib/legate/cli/deployment_commands.rb +934 -0
- data/lib/legate/cli/output_helper.rb +108 -0
- data/lib/legate/cli/session_commands.rb +138 -0
- data/lib/legate/cli/skaffold_commands.rb +223 -0
- data/lib/legate/cli/tool_commands.rb +261 -0
- data/lib/legate/cli/web_commands.rb +182 -0
- data/lib/legate/cli.rb +40 -0
- data/lib/legate/configuration/webhooks.rb +113 -0
- data/lib/legate/configuration.rb +39 -0
- data/lib/legate/definition_store.rb +23 -0
- data/lib/legate/errors.rb +118 -0
- data/lib/legate/event.rb +161 -0
- data/lib/legate/gemini_ai_beta_patch.rb +39 -0
- data/lib/legate/generators/agent_generator.rb +412 -0
- data/lib/legate/generators/code_validator.rb +48 -0
- data/lib/legate/generators/legate/install_generator.rb +35 -0
- data/lib/legate/generators/legate/templates/create_legate_tables.rb.tt +36 -0
- data/lib/legate/generators/legate/templates/initializer.rb +18 -0
- data/lib/legate/generators/runtime_tool_loader.rb +76 -0
- data/lib/legate/generators/tool_generator.rb +408 -0
- data/lib/legate/generators.rb +11 -0
- data/lib/legate/global_definition_registry.rb +506 -0
- data/lib/legate/global_tool_manager.rb +135 -0
- data/lib/legate/llm/adapter.rb +69 -0
- data/lib/legate/llm/gemini.rb +172 -0
- data/lib/legate/llm/ollama.rb +80 -0
- data/lib/legate/llm.rb +34 -0
- data/lib/legate/mcp/client.rb +320 -0
- data/lib/legate/mcp/connection/sse.rb +292 -0
- data/lib/legate/mcp/connection/stdio.rb +273 -0
- data/lib/legate/mcp/connection_manager.rb +103 -0
- data/lib/legate/mcp/server/legate_agent_adapter.rb +170 -0
- data/lib/legate/mcp/server/legate_direct_agent_adapter.rb +140 -0
- data/lib/legate/mcp/server/legate_tool_adapter.rb +119 -0
- data/lib/legate/mcp/tool_wrapper.rb +138 -0
- data/lib/legate/mcp/util/schema_converter.rb +134 -0
- data/lib/legate/mcp.rb +23 -0
- data/lib/legate/plan_executor.rb +375 -0
- data/lib/legate/planner.rb +839 -0
- data/lib/legate/rails/railtie.rb +43 -0
- data/lib/legate/rails.rb +9 -0
- data/lib/legate/redaction.rb +32 -0
- data/lib/legate/session.rb +299 -0
- data/lib/legate/session_service/active_record.rb +300 -0
- data/lib/legate/session_service/base.rb +68 -0
- data/lib/legate/session_service/event_broadcast.rb +74 -0
- data/lib/legate/session_service/in_memory.rb +188 -0
- data/lib/legate/tool/metadata_dsl.rb +122 -0
- data/lib/legate/tool.rb +276 -0
- data/lib/legate/tool_code_generator.rb +103 -0
- data/lib/legate/tool_context.rb +350 -0
- data/lib/legate/tool_loader.rb +39 -0
- data/lib/legate/tool_registry.rb +73 -0
- data/lib/legate/tool_result.rb +61 -0
- data/lib/legate/tools/agent_tool.rb +187 -0
- data/lib/legate/tools/base/http_client.rb +319 -0
- data/lib/legate/tools/base/safe_url.rb +56 -0
- data/lib/legate/tools/base_async_job_tool.rb +91 -0
- data/lib/legate/tools/calculator.rb +89 -0
- data/lib/legate/tools/cat_facts.rb +81 -0
- data/lib/legate/tools/check_job_status_tool.rb +48 -0
- data/lib/legate/tools/current_time_tool.rb +64 -0
- data/lib/legate/tools/echo.rb +43 -0
- data/lib/legate/tools/http_request_tool.rb +105 -0
- data/lib/legate/tools/random_number_tool.rb +64 -0
- data/lib/legate/tools/read_webpage_tool.rb +92 -0
- data/lib/legate/tools/sleepy_tool.rb +74 -0
- data/lib/legate/tools/webhook_tool.rb +146 -0
- data/lib/legate/version.rb +5 -0
- data/lib/legate/web/app.rb +984 -0
- data/lib/legate/web/public/css/main.css +4980 -0
- data/lib/legate/web/public/images/favicon-256.png +0 -0
- data/lib/legate/web/public/images/favicon-32.png +0 -0
- data/lib/legate/web/public/images/legate-logo-dark.png +0 -0
- data/lib/legate/web/public/images/legate-logo-light.png +0 -0
- data/lib/legate/web/public/js/legate.js +616 -0
- data/lib/legate/web/public/styles/main.scss +4402 -0
- data/lib/legate/web/routes/agent_authentication_routes.rb +530 -0
- data/lib/legate/web/routes/agent_definition_routes.rb +803 -0
- data/lib/legate/web/routes/agent_generator_routes.rb +80 -0
- data/lib/legate/web/routes/agent_interaction_routes.rb +734 -0
- data/lib/legate/web/routes/agent_runtime_routes.rb +323 -0
- data/lib/legate/web/routes/api_routes.rb +56 -0
- data/lib/legate/web/routes/authentication_routes.rb +1541 -0
- data/lib/legate/web/routes/core_routes.rb +111 -0
- data/lib/legate/web/routes/documentation_routes.rb +220 -0
- data/lib/legate/web/routes/tool_generator_routes.rb +81 -0
- data/lib/legate/web/routes/tools_ui_routes.rb +207 -0
- data/lib/legate/web/sass_compiler.rb +73 -0
- data/lib/legate/web/views/_active_session_info.slim +25 -0
- data/lib/legate/web/views/_activity_list.slim +55 -0
- data/lib/legate/web/views/_agent_card.slim +56 -0
- data/lib/legate/web/views/_agent_generator_modal.slim +382 -0
- data/lib/legate/web/views/_agent_status_controls.slim +71 -0
- data/lib/legate/web/views/_agent_tool_table.slim +74 -0
- data/lib/legate/web/views/_chat_message.slim +95 -0
- data/lib/legate/web/views/_display_agent_configuration.slim +26 -0
- data/lib/legate/web/views/_display_agent_description.slim +11 -0
- data/lib/legate/web/views/_display_agent_fallback.slim +15 -0
- data/lib/legate/web/views/_display_agent_hierarchy.slim +93 -0
- data/lib/legate/web/views/_display_agent_instruction.slim +17 -0
- data/lib/legate/web/views/_display_agent_mcp.slim +13 -0
- data/lib/legate/web/views/_display_agent_model.slim +17 -0
- data/lib/legate/web/views/_display_agent_name.slim +42 -0
- data/lib/legate/web/views/_display_agent_output_key.slim +26 -0
- data/lib/legate/web/views/_display_agent_type.slim +65 -0
- data/lib/legate/web/views/_edit_agent_configuration.slim +74 -0
- data/lib/legate/web/views/_edit_agent_description.slim +16 -0
- data/lib/legate/web/views/_edit_agent_fallback.slim +25 -0
- data/lib/legate/web/views/_edit_agent_hierarchy.slim +98 -0
- data/lib/legate/web/views/_edit_agent_instruction.slim +49 -0
- data/lib/legate/web/views/_edit_agent_mcp.slim +33 -0
- data/lib/legate/web/views/_edit_agent_model.slim +23 -0
- data/lib/legate/web/views/_edit_agent_output_key.slim +36 -0
- data/lib/legate/web/views/_edit_agent_tools.slim +40 -0
- data/lib/legate/web/views/_edit_agent_type.slim +67 -0
- data/lib/legate/web/views/_session_error.slim +4 -0
- data/lib/legate/web/views/_skeleton.slim +69 -0
- data/lib/legate/web/views/_tool_card.slim +9 -0
- data/lib/legate/web/views/_tool_generator_modal.slim +311 -0
- data/lib/legate/web/views/agent.slim +436 -0
- data/lib/legate/web/views/agent_auth.slim +562 -0
- data/lib/legate/web/views/agents.slim +369 -0
- data/lib/legate/web/views/auth.slim +112 -0
- data/lib/legate/web/views/auth_credential_detail.slim +327 -0
- data/lib/legate/web/views/auth_credentials.slim +261 -0
- data/lib/legate/web/views/auth_debug.slim +94 -0
- data/lib/legate/web/views/auth_mapping_detail.slim +151 -0
- data/lib/legate/web/views/auth_mapping_new.slim +123 -0
- data/lib/legate/web/views/auth_mappings.slim +120 -0
- data/lib/legate/web/views/auth_scheme_detail.slim +274 -0
- data/lib/legate/web/views/auth_schemes.slim +259 -0
- data/lib/legate/web/views/auth_test.slim +418 -0
- data/lib/legate/web/views/chat.slim +192 -0
- data/lib/legate/web/views/docs_index.slim +105 -0
- data/lib/legate/web/views/docs_show.slim +105 -0
- data/lib/legate/web/views/error_404.slim +5 -0
- data/lib/legate/web/views/index.slim +148 -0
- data/lib/legate/web/views/layout.slim +144 -0
- data/lib/legate/web/views/tool_detail.slim +87 -0
- data/lib/legate/web/views/tools.slim +50 -0
- data/lib/legate/web/webhook_listener.rb +367 -0
- data/lib/legate/web.rb +9 -0
- data/lib/legate.rb +220 -0
- data/public/docs/advanced/callbacks.md +828 -0
- data/public/docs/advanced/mcp_schema_conversion.md +59 -0
- data/public/docs/authentication/api_reference/config.md +210 -0
- data/public/docs/authentication/api_reference/credential.md +246 -0
- data/public/docs/authentication/api_reference/encryption.md +218 -0
- data/public/docs/authentication/api_reference/exchanged_credential.md +271 -0
- data/public/docs/authentication/api_reference/excon_middleware.md +175 -0
- data/public/docs/authentication/api_reference/index.md +30 -0
- data/public/docs/authentication/api_reference/scheme.md +250 -0
- data/public/docs/authentication/api_reference/schemes/api_key.md +175 -0
- data/public/docs/authentication/api_reference/schemes/google_service_account.md +221 -0
- data/public/docs/authentication/api_reference/schemes/http_bearer.md +169 -0
- data/public/docs/authentication/api_reference/schemes/oauth2.md +343 -0
- data/public/docs/authentication/api_reference/schemes/oidc.md +73 -0
- data/public/docs/authentication/api_reference/schemes/openid_connect.md +311 -0
- data/public/docs/authentication/api_reference/schemes/service_account.md +287 -0
- data/public/docs/authentication/api_reference/token_manager.md +221 -0
- data/public/docs/authentication/api_reference/token_store.md +146 -0
- data/public/docs/authentication/api_reference/tool_context_extension.md +166 -0
- data/public/docs/authentication/guides/api_key.md +190 -0
- data/public/docs/authentication/guides/bearer.md +172 -0
- data/public/docs/authentication/guides/configuration.md +255 -0
- data/public/docs/authentication/guides/custom_flow.md +523 -0
- data/public/docs/authentication/guides/index.md +24 -0
- data/public/docs/authentication/guides/migration.md +435 -0
- data/public/docs/authentication/guides/oauth2.md +252 -0
- data/public/docs/authentication/guides/oidc.md +241 -0
- data/public/docs/authentication/guides/overview.md +155 -0
- data/public/docs/authentication/guides/secure_storage.md +301 -0
- data/public/docs/authentication/guides/service_account.md +228 -0
- data/public/docs/authentication/guides/token_lifecycle.md +295 -0
- data/public/docs/authentication/guides/web_ui_integration.md +504 -0
- data/public/docs/authentication/index.md +58 -0
- data/public/docs/authentication/troubleshooting/credential_storage.md +550 -0
- data/public/docs/authentication/troubleshooting/environment_variables.md +540 -0
- data/public/docs/authentication/troubleshooting/index.md +11 -0
- data/public/docs/authentication/troubleshooting/oauth2_issues.md +220 -0
- data/public/docs/authentication/troubleshooting/oidc_issues.md +412 -0
- data/public/docs/authentication/troubleshooting/token_refresh.md +338 -0
- data/public/docs/cli/legate_cli_usage.md +363 -0
- data/public/docs/core_concepts/legate_agent_lifecycle.md +124 -0
- data/public/docs/core_concepts/legate_architecture_overview.md +110 -0
- data/public/docs/core_concepts/legate_configuration.md +116 -0
- data/public/docs/core_concepts/legate_definition_store.md +102 -0
- data/public/docs/core_concepts/legate_planner.md +94 -0
- data/public/docs/core_concepts/legate_session_service.md +104 -0
- data/public/docs/error_handling/legate_error_handling.md +122 -0
- data/public/docs/examples.md +199 -0
- data/public/docs/getting_started.md +111 -0
- data/public/docs/guides/agentic_agents.md +137 -0
- data/public/docs/guides/ai_code_generators.md +437 -0
- data/public/docs/guides/auto_loading.md +326 -0
- data/public/docs/guides/configuring_agent_webhooks.md +219 -0
- data/public/docs/guides/http_client_usage.md +264 -0
- data/public/docs/guides/llm_providers.md +137 -0
- data/public/docs/guides/mcp_client_integration.md +232 -0
- data/public/docs/guides/mcp_server_exposure.md +206 -0
- data/public/docs/guides/rails_integration.md +128 -0
- data/public/docs/guides/sending_outbound_webhooks.md +227 -0
- data/public/docs/guides/streaming.md +112 -0
- data/public/docs/guides/webhooks.md +288 -0
- data/public/docs/introduction.md +51 -0
- data/public/docs/multi_agent_systems/advanced_features.md +57 -0
- data/public/docs/multi_agent_systems/agent_delegation.md +190 -0
- data/public/docs/multi_agent_systems/agent_hierarchy.md +49 -0
- data/public/docs/multi_agent_systems/state_management.md +47 -0
- data/public/docs/multi_agent_systems/workflow_agents.md +72 -0
- data/public/docs/tools/legate_built_in_tools.md +332 -0
- data/public/docs/tools/legate_tools_and_registry.md +263 -0
- data/public/docs/web_ui/legate_web_ui.md +137 -0
- metadata +823 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Sequential Agents in Legate
|
|
2
|
+
|
|
3
|
+
Sequential agents are a powerful feature in Legate that allow you to compose multiple specialized agents into a workflow where agents are executed in a predetermined sequence. This approach lets you break down complex tasks into smaller, more manageable components that work together.
|
|
4
|
+
|
|
5
|
+
## How Sequential Agents Work
|
|
6
|
+
|
|
7
|
+
1. **Agent Composition**: A sequential agent is composed of multiple sub-agents, each with its own specialized task.
|
|
8
|
+
2. **Ordered Execution**: Sub-agents are executed in a predefined order, with each agent performing its task before passing control to the next agent.
|
|
9
|
+
3. **State Management**: Each sub-agent can store its results in the session state using the `output_key` attribute, making results available to later sub-agents.
|
|
10
|
+
4. **Coordinated Workflow**: The sequential agent orchestrates the entire process, handling failures and collecting results from each step.
|
|
11
|
+
|
|
12
|
+
## Travel Planner Examples
|
|
13
|
+
|
|
14
|
+
The Legate provides two different implementations of a travel planner using sequential agents, demonstrating different approaches to agent orchestration:
|
|
15
|
+
|
|
16
|
+
### 1. Automatic Sequential Execution (`travel_planner_auto_sequential.rb`)
|
|
17
|
+
|
|
18
|
+
This example demonstrates how to use the built-in `SequentialAgent` class to automatically handle the execution flow:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
bundle exec ruby examples/advanced/workflows/travel_planner_auto_sequential.rb
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Key features:
|
|
25
|
+
- The `SequentialAgent` automatically runs all sub-agents in the defined order
|
|
26
|
+
- Each agent stores its output in session state using `output_key`
|
|
27
|
+
- Subsequent agents can access previous agents' outputs from the session state
|
|
28
|
+
- Visualizes progress with `tty-spinner`
|
|
29
|
+
|
|
30
|
+
### 2. Custom Sequential Execution (`travel_planner_sequential.rb`)
|
|
31
|
+
|
|
32
|
+
This example demonstrates a custom wrapper around `SequentialAgent` for more explicit control:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
bundle exec ruby examples/advanced/workflows/travel_planner_sequential.rb
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Key features:
|
|
39
|
+
- Uses a custom wrapper class to enhance inputs for each agent
|
|
40
|
+
- Shows how to explicitly pass data between agents
|
|
41
|
+
- Provides more control over the execution flow
|
|
42
|
+
- Demonstrates both automatic and custom orchestration approaches
|
|
43
|
+
|
|
44
|
+
### Sub-Agents in the Travel Planner:
|
|
45
|
+
|
|
46
|
+
Both examples use the same set of specialized agents:
|
|
47
|
+
|
|
48
|
+
1. **Destination Research Agent**: Analyzes user preferences and suggests suitable destinations
|
|
49
|
+
- Stores results with `output_key: :destination_results`
|
|
50
|
+
|
|
51
|
+
2. **Itinerary Planner Agent**: Creates a daily itinerary for the chosen destination
|
|
52
|
+
- Stores results with `output_key: :itinerary_results`
|
|
53
|
+
|
|
54
|
+
3. **Budget Estimator Agent**: Calculates costs for the planned trip
|
|
55
|
+
- Stores results with `output_key: :budget_results`
|
|
56
|
+
|
|
57
|
+
4. **Trip Summarizer Agent**: Creates a final summary combining all information
|
|
58
|
+
- Stores results with `output_key: :trip_summary`
|
|
59
|
+
|
|
60
|
+
### Main Sequential Agent:
|
|
61
|
+
|
|
62
|
+
The main agent coordinates all sub-agents by:
|
|
63
|
+
- Setting `agent_type: :sequential` to specify it's a sequential workflow
|
|
64
|
+
- Defining the execution order with `sequential_sub_agents [:destination_research, :itinerary_planner, :budget_estimator, :trip_summarizer]`
|
|
65
|
+
- Storing the final result with `output_key: :complete_travel_plan`
|
|
66
|
+
|
|
67
|
+
## Data Flow Between Agents
|
|
68
|
+
|
|
69
|
+
Sequential agents share data through session state:
|
|
70
|
+
|
|
71
|
+
1. Each sub-agent stores its output in session state using its designated `output_key`
|
|
72
|
+
2. Subsequent agents can retrieve this data using `session_service.get_state(session_id: session_id, key: key_name)`
|
|
73
|
+
3. This creates a data pipeline where each agent builds upon the work of previous agents
|
|
74
|
+
|
|
75
|
+
## Key Concepts Demonstrated
|
|
76
|
+
|
|
77
|
+
- **Agent Composition**: Building complex workflows from simple agents
|
|
78
|
+
- **State Management**: Using `output_key` to pass information between agents
|
|
79
|
+
- **Error Handling**: Properly handling failures in any step of the sequence
|
|
80
|
+
- **Agent Types**: Using the `:sequential` agent type for workflow definition
|
|
81
|
+
- **Orchestration Approaches**: Both automatic and custom orchestration methods
|
|
82
|
+
|
|
83
|
+
## Implementation Approaches
|
|
84
|
+
|
|
85
|
+
### Automatic Sequential Execution
|
|
86
|
+
|
|
87
|
+
The simplest approach where the `SequentialAgent` class handles everything:
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
# Parent Sequential Agent Definition
|
|
91
|
+
travel_planner_def = Legate::AgentDefinition.new.define do |a|
|
|
92
|
+
a.name :travel_planner
|
|
93
|
+
a.description 'Orchestrates the complete travel planning process'
|
|
94
|
+
a.instruction 'You coordinate the travel planning process'
|
|
95
|
+
a.agent_type :sequential # This tells Legate to use SequentialAgent
|
|
96
|
+
a.sequential_sub_agents :destination_research, :itinerary_planner, :budget_estimator, :trip_summarizer
|
|
97
|
+
a.output_key :complete_travel_plan
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Create and run
|
|
101
|
+
travel_planner = Legate::Agents::SequentialAgent.new(
|
|
102
|
+
definition: travel_planner_def,
|
|
103
|
+
sub_agents: [destination_agent, itinerary_agent, budget_agent, summary_agent]
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
result = travel_planner.run_task(
|
|
107
|
+
session_id: session_id,
|
|
108
|
+
user_input: user_input,
|
|
109
|
+
session_service: session_service
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Custom Sequential Execution
|
|
114
|
+
|
|
115
|
+
For more control, you can create a wrapper class:
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
class CustomSequentialAgent
|
|
119
|
+
def initialize(sequential_agent)
|
|
120
|
+
@sequential_agent = sequential_agent
|
|
121
|
+
@sub_agents = sequential_agent.instance_variable_get(:@sub_agents)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def run_task(session_id:, user_input:, session_service:)
|
|
125
|
+
# Run first sub-agent
|
|
126
|
+
result1 = @sub_agents[0].run_task(...)
|
|
127
|
+
|
|
128
|
+
# Get data from first agent and enhance input for second agent
|
|
129
|
+
data1 = session_service.get_state(session_id: session_id, key: :first_agent_output_key)
|
|
130
|
+
enhanced_input = "#{user_input}\n\nPrevious output: #{data1['result']}"
|
|
131
|
+
|
|
132
|
+
# Run second sub-agent with enhanced input
|
|
133
|
+
result2 = @sub_agents[1].run_task(
|
|
134
|
+
session_id: session_id,
|
|
135
|
+
user_input: enhanced_input,
|
|
136
|
+
session_service: session_service
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# Continue for remaining agents...
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Creating Your Own Sequential Agents
|
|
145
|
+
|
|
146
|
+
To create your own sequential agent:
|
|
147
|
+
|
|
148
|
+
1. Define your sub-agent definitions with appropriate specializations
|
|
149
|
+
2. Register all sub-agent definitions with `Legate::GlobalDefinitionRegistry`
|
|
150
|
+
3. Define your main sequential agent with:
|
|
151
|
+
```ruby
|
|
152
|
+
sequential_agent = Legate::AgentDefinition.new.define do |a|
|
|
153
|
+
a.name :your_sequential_agent
|
|
154
|
+
a.description 'Description of your workflow'
|
|
155
|
+
a.instruction 'Instructions for the sequential agent'
|
|
156
|
+
a.agent_type :sequential
|
|
157
|
+
a.sequential_sub_agents [:sub_agent1, :sub_agent2, :sub_agent3]
|
|
158
|
+
a.output_key :final_result_key
|
|
159
|
+
end
|
|
160
|
+
```
|
|
161
|
+
4. Create instances of all sub-agents
|
|
162
|
+
5. Create the sequential agent instance, passing it all sub-agent instances
|
|
163
|
+
6. Start all agents with `agent.start()`
|
|
164
|
+
7. Call `run_task` on the sequential agent
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Example of using Legate::Auth with cookie-based authentication against httpbin.org
|
|
5
|
+
# This example demonstrates how to use cookies for authentication using the Legate tool framework.
|
|
6
|
+
#
|
|
7
|
+
# Usage:
|
|
8
|
+
# ruby examples/advanced/auth/cookie_auth_tool.rb
|
|
9
|
+
|
|
10
|
+
require 'bundler/setup'
|
|
11
|
+
require 'legate'
|
|
12
|
+
require 'legate/auth'
|
|
13
|
+
require 'json'
|
|
14
|
+
require 'securerandom'
|
|
15
|
+
|
|
16
|
+
# Generate a fake session token for demonstration
|
|
17
|
+
COOKIE_VALUE = SecureRandom.hex(16)
|
|
18
|
+
|
|
19
|
+
puts 'Cookie-Based Authentication Example'
|
|
20
|
+
puts '--------------------------------'
|
|
21
|
+
puts "Cookie Value: #{COOKIE_VALUE[0..5]}...#{COOKIE_VALUE[-4..-1]}"
|
|
22
|
+
|
|
23
|
+
# First, let's create a tool class for httpbin.org API
|
|
24
|
+
module Legate
|
|
25
|
+
module Tools
|
|
26
|
+
class HttpbinCookie < Legate::Tool
|
|
27
|
+
include Legate::Tools::Base::HttpClient
|
|
28
|
+
|
|
29
|
+
# Tool metadata
|
|
30
|
+
tool_description 'Makes authenticated requests to httpbin.org using cookies'
|
|
31
|
+
|
|
32
|
+
parameter :endpoint,
|
|
33
|
+
type: :string,
|
|
34
|
+
description: 'The httpbin endpoint to call (e.g., cookies, headers)',
|
|
35
|
+
required: true
|
|
36
|
+
|
|
37
|
+
def initialize(options = {})
|
|
38
|
+
super()
|
|
39
|
+
@auth_scheme = options[:auth_scheme]
|
|
40
|
+
@auth_credential = options[:auth_credential]
|
|
41
|
+
setup_http_client(
|
|
42
|
+
base_url: 'https://httpbin.org',
|
|
43
|
+
options: {
|
|
44
|
+
connect_timeout: 3,
|
|
45
|
+
read_timeout: 3,
|
|
46
|
+
write_timeout: 3
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def perform_execution(params, _context)
|
|
54
|
+
# Extract parameters
|
|
55
|
+
endpoint = params[:endpoint]
|
|
56
|
+
|
|
57
|
+
# Prepare request with authentication
|
|
58
|
+
request = {
|
|
59
|
+
method: :get,
|
|
60
|
+
path: "/#{endpoint}",
|
|
61
|
+
headers: {}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Apply authentication if configured
|
|
65
|
+
request = @auth_scheme.apply_to_request(request, @auth_credential) if @auth_scheme && @auth_credential
|
|
66
|
+
|
|
67
|
+
# Make the request using HttpClient's helper with any auth headers
|
|
68
|
+
response = http_get(
|
|
69
|
+
request[:path],
|
|
70
|
+
headers: request[:headers]
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# Parse and return the response
|
|
74
|
+
begin
|
|
75
|
+
data = JSON.parse(response.body)
|
|
76
|
+
{ status: :success, result: data }
|
|
77
|
+
rescue JSON::ParserError => e
|
|
78
|
+
raise Legate::ToolError, "Failed to parse API response: #{e.message}"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
puts "\nDEMO: Using HttpbinCookie Tool with Cookie Authentication"
|
|
86
|
+
puts '---------------------------------------------------'
|
|
87
|
+
|
|
88
|
+
begin
|
|
89
|
+
# Create session service for token storage
|
|
90
|
+
session_service = Legate::SessionService::InMemory.new
|
|
91
|
+
token_store = Legate::Auth::TokenStore.new(session_service)
|
|
92
|
+
|
|
93
|
+
# Create an API Key scheme (we'll use this for cookie auth)
|
|
94
|
+
scheme = Legate::Auth::Schemes::ApiKey.new
|
|
95
|
+
|
|
96
|
+
# Create a credential with cookie configuration
|
|
97
|
+
credential = Legate::Auth::Credential.new(
|
|
98
|
+
auth_type: :api_key,
|
|
99
|
+
api_key: COOKIE_VALUE,
|
|
100
|
+
location: 'cookie',
|
|
101
|
+
name: 'session_token'
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Create our HttpbinCookie tool instance with authentication
|
|
105
|
+
cookie_tool = Legate::Tools::HttpbinCookie.new(
|
|
106
|
+
auth_scheme: scheme,
|
|
107
|
+
auth_credential: credential
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Example endpoints to test
|
|
111
|
+
endpoints = %w[cookies headers]
|
|
112
|
+
|
|
113
|
+
# Test each endpoint
|
|
114
|
+
endpoints.each do |endpoint|
|
|
115
|
+
puts "\nTesting endpoint: /#{endpoint}"
|
|
116
|
+
|
|
117
|
+
begin
|
|
118
|
+
result = cookie_tool.execute(
|
|
119
|
+
endpoint: endpoint
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
if result[:status] == :success
|
|
123
|
+
response_data = result[:result]
|
|
124
|
+
|
|
125
|
+
case endpoint
|
|
126
|
+
when 'cookies'
|
|
127
|
+
puts 'Cookies in request:'
|
|
128
|
+
puts JSON.pretty_generate(response_data['cookies'])
|
|
129
|
+
when 'headers'
|
|
130
|
+
puts 'Headers in request:'
|
|
131
|
+
puts JSON.pretty_generate(response_data['headers'])
|
|
132
|
+
end
|
|
133
|
+
else
|
|
134
|
+
puts "Error: #{result[:error_message]}"
|
|
135
|
+
end
|
|
136
|
+
rescue StandardError => e
|
|
137
|
+
puts "Error testing #{endpoint}: #{e.message}"
|
|
138
|
+
puts e.backtrace.join("\n") if ENV['DEBUG']
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
rescue StandardError => e
|
|
142
|
+
puts "Error: #{e.message}"
|
|
143
|
+
puts e.backtrace.join("\n") if ENV['DEBUG']
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
puts "\nExample complete."
|