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
|
A simple, composable LLM agent. |
|
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:
objectConfiguration for Agent behavior and LLM parameters.
- 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:
objectA 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:
- __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 agentprovider (
Optional[str]) – LLM provider to use (openai, anthropic, cohere)persist_state (
bool) – Whether to persist conversation statesystem_message (
Optional[str]) – System message to set agent behaviorconfig (
Optional[Dict[str,Any]]) – Additional configuration parametersmemory_enabled (
bool) – Whether to enable vector memory capabilitiesmemory_config (
Optional[Dict[str,Any]]) – Configuration for memory systemknowledge_base (
Optional[str]) – Path to knowledge base files to auto-index
- Raises:
ValueError – If name is empty or configuration is invalid
ProviderError – If provider setup fails
- chat(message)[source]
Send a message to the agent and get a response.
- Parameters:
- Return type:
- Returns:
Agent’s response as a string
- Raises:
ValueError – If message is empty or None
PravalError – If response generation fails
- 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:
- 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.
- broadcast_knowledge(knowledge, channel='main')[source]
Broadcast knowledge to all agents in the reef.
- request_knowledge(from_agent, request, timeout=30)[source]
Request knowledge from another agent with 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:
- create_knowledge_reference(content, importance=0.8)[source]
Create knowledge references for lightweight spores