khora_core/agent/
mod.rs

1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Traits for autonomous engine subsystems (Agents).
16
17use crate::control::gorna::AgentId;
18use crate::control::gorna::{AgentStatus, NegotiationRequest, NegotiationResponse, ResourceBudget};
19use crate::EngineContext;
20use std::any::Any;
21
22/// The foundational interface for an Intelligent Subsystem Agent (ISA).
23///
24/// Each major subsystem (Rendering, Physics, etc.) implements this trait to
25/// participate in the engine's dynamic resource negotiation (GORNA).
26pub trait Agent: Send + Sync {
27    /// Returns the unique identifier for this agent.
28    fn id(&self) -> AgentId;
29
30    /// Negotiates with the DCC to determine the best execution strategy
31    /// given the current global resource constraints and priorities.
32    fn negotiate(&mut self, request: NegotiationRequest) -> NegotiationResponse;
33
34    /// Applies a resource budget issued by the DCC.
35    /// The agent must adjust its internal logic (e.g., LOD, quality settings)
36    /// to stay within the allocated limits.
37    fn apply_budget(&mut self, budget: ResourceBudget);
38
39    /// Periodically updates the agent's internal state.
40    fn update(&mut self, context: &mut EngineContext<'_>);
41
42    /// Reports the current status and health of the agent.
43    fn report_status(&self) -> AgentStatus;
44
45    /// Executes the agent's primary function for this frame.
46    /// Called after update(), this is where the agent performs its main work.
47    fn execute(&mut self);
48
49    /// Allows downcasting to concrete agent types.
50    fn as_any(&self) -> &dyn Any;
51
52    /// Allows mutable downcasting to concrete agent types.
53    fn as_any_mut(&mut self) -> &mut dyn Any;
54}