pub struct PersonaGraph { /* private fields */ }Expand description
Persona graph for managing entity relationships
Maintains a graph structure of personas and their relationships, enabling coherent persona switching across related entities.
Implementations§
Source§impl PersonaGraph
impl PersonaGraph
Sourcepub fn add_node(&self, node: PersonaNode)
pub fn add_node(&self, node: PersonaNode)
Add a persona node to the graph
Sourcepub fn get_node(&self, persona_id: &str) -> Option<PersonaNode>
pub fn get_node(&self, persona_id: &str) -> Option<PersonaNode>
Get a node by persona ID
Sourcepub fn add_edge(&self, from: String, to: String, relationship_type: String)
pub fn add_edge(&self, from: String, to: String, relationship_type: String)
Add an edge between two personas
Sourcepub fn get_edges_from(&self, persona_id: &str) -> Vec<Edge>
pub fn get_edges_from(&self, persona_id: &str) -> Vec<Edge>
Get all edges from a persona
Sourcepub fn get_edges_to(&self, persona_id: &str) -> Vec<Edge>
pub fn get_edges_to(&self, persona_id: &str) -> Vec<Edge>
Get all edges to a persona
Find all related personas using BFS traversal
Traverses the graph starting from the given persona ID, following relationships of the specified types.
§Arguments
start_persona_id- Starting persona IDrelationship_types- Optional filter for relationship types to followmax_depth- Maximum traversal depth (None = unlimited)
§Returns
Vector of persona IDs reachable from the start persona
Find all related personas using DFS traversal
Traverses the graph starting from the given persona ID, following relationships of the specified types.
§Arguments
start_persona_id- Starting persona IDrelationship_types- Optional filter for relationship types to followmax_depth- Maximum traversal depth (None = unlimited)
§Returns
Vector of persona IDs reachable from the start persona
Sourcepub fn get_subgraph(
&self,
start_persona_id: &str,
) -> (Vec<PersonaNode>, Vec<Edge>)
pub fn get_subgraph( &self, start_persona_id: &str, ) -> (Vec<PersonaNode>, Vec<Edge>)
Get the entire subgraph starting from a persona
Returns all nodes and edges reachable from the start persona.
Sourcepub fn get_all_nodes(&self) -> Vec<PersonaNode>
pub fn get_all_nodes(&self) -> Vec<PersonaNode>
Get all nodes in the graph
Sourcepub fn remove_node(&self, persona_id: &str)
pub fn remove_node(&self, persona_id: &str)
Remove a node and all its edges
Sourcepub fn get_stats(&self) -> GraphStats
pub fn get_stats(&self) -> GraphStats
Get graph statistics
Sourcepub fn link_entity_types(
&self,
from_persona_id: &str,
from_entity_type: &str,
to_persona_id: &str,
to_entity_type: &str,
)
pub fn link_entity_types( &self, from_persona_id: &str, from_entity_type: &str, to_persona_id: &str, to_entity_type: &str, )
Link personas across entity types automatically
Creates relationships between personas based on common entity type patterns:
- user → has_orders → order
- user → has_accounts → account
- order → has_payments → payment
- user → has_webhooks → webhook
- user → has_tcp_messages → tcp_message
§Arguments
from_persona_id- Source persona IDfrom_entity_type- Source entity type (e.g., “user”, “order”)to_persona_id- Target persona IDto_entity_type- Target entity type (e.g., “order”, “payment”)
Find all related personas of a specific entity type
Traverses the graph to find all personas of the specified entity type that are related to the starting persona.
§Arguments
start_persona_id- Starting persona IDtarget_entity_type- Entity type to find (e.g., “order”, “payment”)relationship_type- Optional relationship type filter (e.g., “has_orders”)
§Returns
Vector of persona IDs matching the criteria
Sourcepub fn get_or_create_node_with_links(
&self,
persona_id: &str,
entity_type: &str,
related_entity_id: Option<&str>,
related_entity_type: Option<&str>,
) -> PersonaNode
pub fn get_or_create_node_with_links( &self, persona_id: &str, entity_type: &str, related_entity_id: Option<&str>, related_entity_type: Option<&str>, ) -> PersonaNode
Get or create a persona node and link it to related entities
This is a convenience method that creates a persona node if it doesn’t exist and automatically establishes relationships based on entity type patterns.
§Arguments
persona_id- Persona IDentity_type- Entity type (e.g., “user”, “order”, “payment”)related_entity_id- Optional related entity ID to link torelated_entity_type- Optional related entity type
Source§impl PersonaGraph
impl PersonaGraph
Sourcepub fn to_visualization(&self) -> GraphVisualization
pub fn to_visualization(&self) -> GraphVisualization
Generate visualization data for the graph
Trait Implementations§
Source§impl Clone for PersonaGraph
impl Clone for PersonaGraph
Source§fn clone(&self) -> PersonaGraph
fn clone(&self) -> PersonaGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more