praval.core.agent

Core Agent class for the Praval framework.

The Agent class provides a simple, composable interface for LLM-based conversations with support for multiple providers, tools, and state persistence.

Classes

Agent(name[, provider, persist_state, ...])

A simple, composable LLM agent.

AgentConfig([provider, temperature, ...])

Configuration for Agent behavior and LLM parameters.

class praval.core.agent.AgentConfig(provider=None, temperature=0.7, max_tokens=1000, system_message=None)[source]

Bases: object

Configuration for Agent behavior and LLM parameters.

Parameters:
  • provider (str | None)

  • temperature (float)

  • max_tokens (int)

  • system_message (str | None)

provider: Optional[str] = None
temperature: float = 0.7
max_tokens: int = 1000
system_message: Optional[str] = None
__post_init__()[source]

Validate configuration parameters.

__init__(provider=None, temperature=0.7, max_tokens=1000, system_message=None)
Parameters:
  • provider (str | None)

  • temperature (float)

  • max_tokens (int)

  • system_message (str | None)

Return type:

None

class praval.core.agent.Agent(name, provider=None, persist_state=False, system_message=None, config=None, memory_enabled=False, memory_config=None, knowledge_base=None)[source]

Bases: object

A simple, composable LLM agent.

The Agent class provides the core functionality for LLM-based conversations with support for multiple providers, conversation history, tools, and state persistence.

Examples

Basic usage: >>> agent = Agent(“assistant”) >>> response = agent.chat(“Hello!”)

With persistence: >>> agent = Agent(“my_agent”, persist_state=True) >>> agent.chat(“Remember this conversation”)

With tools: >>> agent = Agent(“calculator”) >>> @agent.tool >>> def add(x: int, y: int) -> int: … return x + y

Parameters:
  • name (str)

  • provider (str | None)

  • persist_state (bool)

  • system_message (str | None)

  • config (Dict[str, Any] | None)

  • memory_enabled (bool)

  • memory_config (Dict[str, Any] | None)

  • knowledge_base (str | None)

__init__(name, provider=None, persist_state=False, system_message=None, config=None, memory_enabled=False, memory_config=None, knowledge_base=None)[source]

Initialize a new Agent.

Parameters:
  • name (str) – Unique identifier for this agent

  • provider (Optional[str]) – LLM provider to use (openai, anthropic, cohere)

  • persist_state (bool) – Whether to persist conversation state

  • system_message (Optional[str]) – System message to set agent behavior

  • config (Optional[Dict[str, Any]]) – Additional configuration parameters

  • memory_enabled (bool) – Whether to enable vector memory capabilities

  • memory_config (Optional[Dict[str, Any]]) – Configuration for memory system

  • knowledge_base (Optional[str]) – Path to knowledge base files to auto-index

Raises:
chat(message)[source]

Send a message to the agent and get a response.

Parameters:

message (Optional[str]) – User message to send to the agent

Return type:

str

Returns:

Agent’s response as a string

Raises:
tool(func)[source]

Decorator to register a function as a tool for the agent.

Parameters:

func (Callable) – Function to register as a tool

Return type:

Callable

Returns:

The original function (unchanged)

Raises:

ValueError – If function lacks proper type hints

send_knowledge(to_agent, knowledge, channel='main')[source]

Send knowledge to another agent through the reef.

Parameters:
  • to_agent (str) – Name of the target agent

  • knowledge (Dict[str, Any]) – Knowledge data to send

  • channel (str) – Reef channel to use (default: “main”)

Return type:

str

Returns:

Spore ID of the sent message

broadcast_knowledge(knowledge, channel='main')[source]

Broadcast knowledge to all agents in the reef.

Parameters:
  • knowledge (Dict[str, Any]) – Knowledge data to broadcast

  • channel (str) – Reef channel to use (default: “main”)

Return type:

str

Returns:

Spore ID of the broadcast message

request_knowledge(from_agent, request, timeout=30)[source]

Request knowledge from another agent with timeout.

Parameters:
  • from_agent (str) – Name of the agent to request from

  • request (Dict[str, Any]) – Request data

  • timeout (int) – Timeout in seconds

Return type:

Optional[Dict[str, Any]]

Returns:

Response data or None if timeout

on_spore_received(spore)[source]

Handle received spores from the reef.

This is a default implementation that can be overridden by subclasses for custom spore handling.

Parameters:

spore – The received Spore object

Return type:

None

subscribe_to_channel(channel_name)[source]

Subscribe this agent to a reef channel.

Parameters:

channel_name (str) – Name of the channel to subscribe to

Return type:

None

unsubscribe_from_channel(channel_name)[source]

Unsubscribe this agent from a reef channel.

Parameters:

channel_name (str) – Name of the channel to unsubscribe from

Return type:

None

set_spore_handler(handler)[source]

Set a custom spore handler for this agent.

Parameters:

handler (Callable) – Function that takes a Spore object and handles it

Return type:

None

remember(content, importance=0.5, memory_type='short_term')[source]

Store a memory

Parameters:
  • content (str) – The content to remember

  • importance (float) – Importance score (0.0 to 1.0)

  • memory_type (str) – Type of memory (“short_term”, “semantic”, “episodic”)

Return type:

Optional[str]

Returns:

Memory ID if successful, None otherwise

recall(query, limit=5, similarity_threshold=0.1)[source]

Recall memories based on a query

Parameters:
  • query (str) – Search query

  • limit (int) – Maximum number of results

  • similarity_threshold (float) – Minimum similarity score

Return type:

List

Returns:

List of MemoryEntry objects

recall_by_id(memory_id)[source]

Recall a specific memory by ID (for resolving spore references)

Return type:

List

Parameters:

memory_id (str)

get_conversation_context(turns=10)[source]

Get recent conversation context

Return type:

List

Parameters:

turns (int)

create_knowledge_reference(content, importance=0.8)[source]

Create knowledge references for lightweight spores

Parameters:
  • content (str) – Knowledge content to store and reference

  • importance (float) – Importance threshold

Return type:

List[str]

Returns:

List of knowledge reference IDs

resolve_spore_knowledge(spore)[source]

Resolve knowledge references in a spore

Parameters:

spore – Spore object with potential knowledge references

Return type:

Dict[str, Any]

Returns:

Complete knowledge including resolved references

send_lightweight_knowledge(to_agent, large_content, summary, channel='main')[source]

Send large knowledge as lightweight spore with references

Parameters:
  • to_agent (str) – Target agent

  • large_content (str) – Large content to reference

  • summary (str) – Brief summary for the spore

  • channel (str) – Communication channel

Return type:

str

Returns:

Spore ID