Of course. Based on the provided foundation
codebase and the jido
/jido_action
guides, here is a proposed architecture for the new jido
module, along with an enhanced example application that showcases the full power of the integrated stack.
Architecture Proposal: The Jido
Application Layer
The foundation
project provides robust, production-grade infrastructure primitives (Registry, Coordination, Error Handling, etc.). The jido
and jido_action
guides describe a developer-friendly framework for building agents and workflows. The goal is to build the jido
framework on top of the foundation
platform, creating a powerful, layered system.
The new module, which we will call Jido
, will live in lib/jido/
(as lib/nextModule
implies). It will not reinvent the wheel but will serve as the primary interface for developers, intelligently composing foundation
primitives and integrating the jido_action
execution engine.
Directory Structure for lib/jido/
lib/
├── jido/
│ ├── agent/
│ │ ├── directive.ex # Defines agent directives (Enqueue, RegisterAction, Spawn, etc.)
│ │ ├── runner.ex # Runner behaviour (Simple, Chain)
│ │ ├── server.ex # The GenServer implementation for stateful agents
│ │ └── supervisor.ex # Agent's own child supervisor
│ ├── sensor/
│ │ └── heartbeat.ex # Example built-in sensor
│ ├── signal/
│ │ ├── router.ex # Signal routing logic (like in jido_foundation)
│ │ └── signal.ex # The Signal struct and helpers
│ ├── agent.ex # The main `use Jido.Agent` macro
│ ├── application.ex # The Jido OTP application
│ ├── sensor.ex # The `use Jido.Sensor` macro
│ ├── skill.ex # The `use Jido.Skill` macro
│ └── supervisor.ex # Top-level Jido supervisor
└── jido.ex # Top-level facade (optional)
Key Integration Points and Architectural Decisions
Jido.Agent
(The Core Abstraction):- The
use Jido.Agent
macro will be the primary entry point for developers. - It will handle state management, instruction queuing, and action registration as described in the guides.
- Integration: When a stateful agent (
Jido.Agent.Server
) starts, it will automatically callFoundation.register/4
to register itself with the configuredregistry_impl
. The metadata will be rich, including the agent’s name, capabilities (derived from its actions and skills), and initial health status. - It will start its own
Jido.Agent.Supervisor
to manage its child processes (sensors or other agents).
- The
Jido.Agent.Server
(The Stateful Engine):- This GenServer is the runtime for a stateful agent. It manages the agent’s state, instruction queue, and lifecycle.
- Integration: It will trap exits and, upon termination, use
Foundation.unregister/2
to clean up its entry in the registry. This leveragesFoundation
’s robust monitoring capabilities.
Jido.Action
andJido.Exec
(The Execution Layer):- The
Jido
module will not reimplement action execution. It will use the providedjido_action
library’sJido.Exec
module. - Integration: The
Jido.Agent.Runner
(e.g.,ChainRunner
) will callJido.Exec.run/4
. We will enhance or wrapJido.Exec
to integrate withFoundation
:- Resource Management: Before executing a resource-intensive action (marked with a new
@tag :heavy
), it will callFoundation.ResourceManager.acquire_resource/2
. - Circuit Breakers: For actions that involve external calls (
@tag :external_api
), it will wrap the execution inFoundation.execute_protected/4
. This provides resilience without the developer needing to think about it.
- Resource Management: Before executing a resource-intensive action (marked with a new
- The
Jido.Signal
(The Communication Bus):- The
JidoFoundation.SignalRouter
is a perfect prototype. This will be formalized intoJido.Signal.Router
. - Integration: The router will use
telemetry
as its underlying transport. Agents emit signals, which are captured by the router. The router then usesFoundation.query/2
to find agents subscribed to specific signal patterns (e.g., agents with a skill that handles"error.*"
). This is a powerful, decoupled communication pattern.
- The
Jido.Skill
(The Extensibility Layer):- A
Skill
will be a module that bundles actions, routes, and sensors. - When an agent
use
s aSkill
, the agent’sstart_link
will automatically:- Register the skill’s actions.
- Add the skill’s routes to its
Jido.Signal.Router
. - Start the skill’s sensors under its own supervisor.
- Integration: This allows complex capabilities, built on
Foundation
, to be encapsulated and reused. For example, aMLFoundation.TeamOrchestration
skill could be added to an agent to give it team management abilities.
- A
Enhanced Example Application: Distributed Content Moderation System
This example goes beyond simple CRUD-like actions to showcase a dynamic, resilient, and observable multi-agent system built on the full stack.
Goal: Create a system that receives content (text, images), analyzes it for policy violations, and takes appropriate action.
1. The Agents
TriageAgent
(The Router):- Role: The system’s entry point. Receives new content submissions.
- Logic:
- Receives a signal like
{type: "content.submitted", data: %{content_type: :text, payload: "..."}}
. - Uses
MABEAM.Discovery.find_capable_and_healthy(:text_analysis)
to find an available text analysis agent. - If no agent is available, it can either hold the content in a queue or use a
Foundation.Coordination
primitive to request a new analysis agent be spawned. - Forwards the content to the chosen analysis agent.
- Receives a signal like
TextAnalysisAgent
(The Specialist):- Role: Analyzes text for violations.
- Skill:
use Jido.Skill, TextAnalysisSkill
- Actions within the Skill:
CheckToxicityAction
: Calls an external AI/LLM to score for toxicity. Integration: This action is tagged@tag :external_api
and its execution is wrapped byFoundation.execute_protected
to provide circuit-breaker resilience. If the API is down, it can return a cached/default result.DetectPIIAction
: Scans for Personally Identifiable Information.GenerateAnalysisReportAction
: Compiles the results.
- Workflow: Chains these actions. Upon completion, emits a
content.analysis.completed
signal with the report.
ImageAnalysisAgent
(The Heavy-Lifting Specialist):- Role: Analyzes images for violations. This is a resource-intensive task.
- Skill:
use Jido.Skill, ImageAnalysisSkill
- Actions within the Skill:
AnalyzeImageAction
: Performs the analysis. Integration: This action is tagged@tag :heavy
. BeforeJido.Exec
runs it, it callsFoundation.ResourceManager.acquire_resource(:image_processing)
. If resources are unavailable, the request is rejected or requeued, preventing system overload. After completion, the resource is released.
- Workflow: Emits
content.analysis.completed
signal.
PolicyEnforcementAgent
(The Decider):- Role: Subscribes to
content.analysis.completed
signals. Makes the final moderation decision. - Logic:
- Receives the analysis report.
- If the report is ambiguous, it uses
Foundation.Coordination.start_consensus
with otherPolicyEnforcementAgent
instances to vote on the final action. - Executes a final action chain:
[DetermineAction, ExecuteAction, LogAction]
.
ExecuteAction
could beBanUserAction
,DeleteContentAction
, etc. Integration: These critical actions are wrapped inFoundation.AtomicTransaction
to ensure that, for example, a user is marked as banned and their content is deleted in a single, all-or-nothing operation.
- Role: Subscribes to
2. How it Showcases the Full Stack
jido
(Application Framework): Provides the high-levelAgent
,Skill
,Sensor
, andAction
abstractions that make the logic easy to write and reason about. The entire workflow is described as a series of Jido actions and signals.jido_action
(Execution Engine): TheJido.Exec
andJido.Exec.Chain
modules are used by the agents’ runners to execute the action pipelines, handling parameter passing and result aggregation.foundation
(The Platform):Foundation.Registry
(MABEAM.AgentRegistry
): All agents are registered. TheTriageAgent
uses it for dynamic, health-aware discovery of workers. This is far more robust than hardcoding PIDs.Foundation.Infrastructure
(MABEAM.AgentInfrastructure
):- The
TextAnalysisAgent
’s external API call is protected by a circuit breaker. - The
ImageAnalysisAgent
’s heavy workload is managed by theResourceManager
, preventing it from crashing the node.
- The
Foundation.Coordination
(MABEAM.AgentCoordination
): ThePolicyEnforcementAgent
uses consensus to make resilient, distributed decisions, avoiding a single point of failure in judgment.Foundation.AtomicTransaction
: ThePolicyEnforcementAgent
uses atomic transactions to ensure critical, multi-step state changes (like banning a user and deleting their content) are applied consistently.Foundation.PerformanceMonitor
: Could be used by aSystemMonitorAgent
to track action execution times and system load, triggering alerts or auto-scaling actions.
This example demonstrates a system that is not only logically sound (separating triage, analysis, and enforcement) but also robust, observable, and scalable, thanks to the deep integration of the developer-friendly Jido
framework with the production-ready Foundation
platform.