use std::any::Any;
use std::sync::Arc;
use gadk_session::Event;
use crate::agent::LiveAgent;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AgentType {
LlmAgent,
LoopAgent,
SequentialAgent,
ParallelAgent,
WorkflowAgent,
CustomAgent,
RemoteAgent,
}
impl AgentType {
pub fn as_str(&self) -> &'static str {
match self {
AgentType::LlmAgent => "LLMAgent",
AgentType::LoopAgent => "LoopAgent",
AgentType::SequentialAgent => "SequentialAgent",
AgentType::ParallelAgent => "ParallelAgent",
AgentType::WorkflowAgent => "WorkflowAgent",
AgentType::CustomAgent => "CustomAgent",
AgentType::RemoteAgent => "RemoteAgent",
}
}
}
#[doc(hidden)]
#[derive(Clone)]
pub struct AgentState {
pub agent_type: AgentType,
pub config: Option<Arc<dyn Any + Send + Sync>>,
#[allow(clippy::type_complexity)] pub on_before_agent_callback_event: Option<Arc<dyn Fn(&mut Event) + Send + Sync>>,
pub live: Option<Arc<dyn LiveAgent>>,
}
impl AgentState {
pub fn key(&self) -> usize {
self.config
.as_ref()
.map_or(0, |c| Arc::as_ptr(c).cast::<()>() as usize)
}
}
impl std::fmt::Debug for AgentState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AgentState")
.field("agent_type", &self.agent_type)
.field("key", &self.key())
.field("live", &self.live.is_some())
.finish_non_exhaustive()
}
}