praval.core.reef๏ƒ

Reef Communication System for Praval Framework.

Like coral reefs facilitate communication between polyps through chemical and biological signals, this system enables knowledge-first communication between agents through structured JSON message queues.

Components: - Spores: JSON messages containing knowledge, data, or requests - ReefChannel: Named message channels within the reef - Reef: The message queue network connecting all agents

Functions

get_reef()

Get the global reef instance.

Classes

Reef([default_max_workers])

The Reef manages all communication channels and facilitates agent communication.

ReefChannel(name[,ย max_capacity,ย max_workers])

A message channel within the reef.

Spore(id,ย spore_type,ย from_agent,ย to_agent,ย ...)

A spore is a knowledge-carrying message that flows through the reef.

SporeType(*values)

Types of spores that can flow through the reef.

class praval.core.reef.SporeType(*values)[source]๏ƒ

Bases: Enum

Types of spores that can flow through the reef.

KNOWLEDGE = 'knowledge'๏ƒ
REQUEST = 'request'๏ƒ
RESPONSE = 'response'๏ƒ
BROADCAST = 'broadcast'๏ƒ
NOTIFICATION = 'notification'๏ƒ
class praval.core.reef.Spore(id, spore_type, from_agent, to_agent, knowledge, created_at, expires_at=None, priority=5, reply_to=None, metadata=None, knowledge_references=None, data_references=None)[source]๏ƒ

Bases: object

A spore is a knowledge-carrying message that flows through the reef.

Like biological spores, each carries: - Genetic material (knowledge/data) - Identification markers (metadata) - Survival instructions (processing hints)

Spores can carry either direct knowledge or lightweight references to knowledge stored in vector memory, following the principle that โ€œlight spores travel far.โ€

Parameters:
id: str๏ƒ
spore_type: SporeType๏ƒ
from_agent: str๏ƒ
to_agent: Optional[str]๏ƒ
knowledge: Dict[str, Any]๏ƒ
created_at: datetime๏ƒ
expires_at: Optional[datetime] = None๏ƒ
priority: int = 5๏ƒ
reply_to: Optional[str] = None๏ƒ
metadata: Dict[str, Any] = None๏ƒ
knowledge_references: List[str] = None๏ƒ
data_references: List[str] = None๏ƒ
to_json()[source]๏ƒ

Serialize spore to JSON for transmission.

Return type:

str

classmethod from_json(json_str)[source]๏ƒ

Deserialize spore from JSON.

Return type:

Spore

Parameters:

json_str (str)

is_expired()[source]๏ƒ

Check if spore has expired.

Return type:

bool

add_knowledge_reference(reference_id)[source]๏ƒ

Add a reference to stored knowledge

Parameters:

reference_id (str)

add_data_reference(reference_uri)[source]๏ƒ

Add a reference to storage system data

Parameters:

reference_uri (str)

has_knowledge_references()[source]๏ƒ

Check if spore has knowledge references

Return type:

bool

has_data_references()[source]๏ƒ

Check if spore has data references

Return type:

bool

has_any_references()[source]๏ƒ

Check if spore has any kind of references

Return type:

bool

get_spore_size_estimate()[source]๏ƒ

Estimate spore size for lightweight transmission

Return type:

int

__init__(id, spore_type, from_agent, to_agent, knowledge, created_at, expires_at=None, priority=5, reply_to=None, metadata=None, knowledge_references=None, data_references=None)๏ƒ
Parameters:
Return type:

None

class praval.core.reef.ReefChannel(name, max_capacity=1000, max_workers=4)[source]๏ƒ

Bases: object

A message channel within the reef.

Like channels in a coral reef, they: - Have directional flow patterns - Can carry multiple spores simultaneously - Have capacity limits (to prevent overwhelming) - Can experience turbulence (message loss/delays)

Parameters:
  • name (str)

  • max_capacity (int)

  • max_workers (int)

__init__(name, max_capacity=1000, max_workers=4)[source]๏ƒ
Parameters:
  • name (str)

  • max_capacity (int)

  • max_workers (int)

send_spore(spore)[source]๏ƒ

Send a spore through this channel.

Return type:

bool

Parameters:

spore (Spore)

subscribe(agent_name, handler)[source]๏ƒ

Subscribe an agent to receive spores from this channel.

Return type:

None

Parameters:
unsubscribe(agent_name)[source]๏ƒ

Unsubscribe an agent from this channel.

Return type:

None

Parameters:

agent_name (str)

get_spores_for_agent(agent_name, limit=10)[source]๏ƒ

Get recent spores for a specific agent (polling interface).

Return type:

List[Spore]

Parameters:
  • agent_name (str)

  • limit (int)

cleanup_expired()[source]๏ƒ

Remove expired spores from the channel.

Return type:

int

get_stats()[source]๏ƒ

Get channel statistics.

Return type:

Dict[str, Any]

shutdown(wait=True)[source]๏ƒ

Shutdown the channelโ€™s thread pool.

Return type:

None

Parameters:

wait (bool)

class praval.core.reef.Reef(default_max_workers=4)[source]๏ƒ

Bases: object

The Reef manages all communication channels and facilitates agent communication.

Like a coral reef ecosystem, it: - Maintains multiple communication channels - Enables knowledge flow between polyps (agents) - Supports both direct and broadcast communication - Provides network health monitoring

Parameters:

default_max_workers (int)

__init__(default_max_workers=4)[source]๏ƒ
Parameters:

default_max_workers (int)

create_channel(name, max_capacity=1000, max_workers=None)[source]๏ƒ

Create a new reef channel.

Return type:

ReefChannel

Parameters:
  • name (str)

  • max_capacity (int)

  • max_workers (int | None)

get_channel(name)[source]๏ƒ

Get a reef channel by name.

Return type:

Optional[ReefChannel]

Parameters:

name (str)

send(from_agent, to_agent, knowledge, spore_type=SporeType.KNOWLEDGE, channel=None, priority=5, expires_in_seconds=None, reply_to=None, knowledge_references=None, auto_reference_large_knowledge=True)[source]๏ƒ

Send a spore through the reef.

Return type:

str

Parameters:
  • from_agent (str)

  • to_agent (str | None)

  • knowledge (Dict[str, Any])

  • spore_type (SporeType)

  • channel (str)

  • priority (int)

  • expires_in_seconds (int | None)

  • reply_to (str | None)

  • knowledge_references (List[str] | None)

  • auto_reference_large_knowledge (bool)

broadcast(from_agent, knowledge, channel=None)[source]๏ƒ

Broadcast knowledge to all agents in the reef.

Return type:

str

Parameters:
system_broadcast(knowledge, channel=None)[source]๏ƒ

Broadcast system-level messages to all agents in a channel.

Return type:

str

Parameters:
request(from_agent, to_agent, request, channel=None, expires_in_seconds=300)[source]๏ƒ

Send a knowledge request to another agent.

Return type:

str

Parameters:
reply(from_agent, to_agent, response, reply_to_spore_id, channel=None)[source]๏ƒ

Reply to a knowledge request.

Return type:

str

Parameters:
subscribe(agent_name, handler, channel=None)[source]๏ƒ

Subscribe an agent to receive spores from a channel.

Return type:

None

Parameters:
get_network_stats()[source]๏ƒ

Get statistics about the reef network.

Return type:

Dict[str, Any]

shutdown(wait=True)[source]๏ƒ

Shutdown the reef and all its channels.

Return type:

None

Parameters:

wait (bool)

create_knowledge_reference_spore(from_agent, to_agent, knowledge_summary, knowledge_references, spore_type=SporeType.KNOWLEDGE, channel=None)[source]๏ƒ

Create a lightweight spore with knowledge references

This follows the reef principle: โ€œlight spores travel farโ€

Return type:

str

Parameters:
resolve_knowledge_references(spore, memory_manager)[source]๏ƒ

Resolve knowledge references in a spore to actual knowledge

Parameters:
  • spore (Spore) โ€“ The spore with knowledge references

  • memory_manager โ€“ Agentโ€™s memory manager to resolve references

Return type:

Dict[str, Any]

Returns:

Combined knowledge from references

praval.core.reef.get_reef()[source]๏ƒ

Get the global reef instance.

Return type:

Reef