This document provides reference documentation for the Cognitive Engine's public APIs.
Module: core.engine
Class: CognitiveEngine
Main orchestration engine that coordinates all cognitive layers.
def __init__(config: Optional[Config] = None)
Parameters:
config (Optional[Config]): Configuration object. If None, uses default config.Example:
from core.engine import CognitiveEngine
engine = CognitiveEngine()
def process(self, input: str) -> ProcessResult
Process a user input through the cognitive engine.
Parameters:
input (str): User query or problem statementReturns:
ProcessResult: Object containing final output and metadataExample:
result = engine.process("What is the meaning of life?")
print(result.final_output)
print(result.iteration_count)
print(result.reasoning_trace)
def initialize_layers(self) -> None
Initialize all cognitive layers (Interpreter, Generator, Deliberator, Committer, Meta).
Example:
engine.initialize_layers()
def get_thought_graph(self) -> ThoughtGraph
Get the current thought graph containing all generated thoughts.
Returns:
ThoughtGraph: Graph of interconnected thoughtsExample:
graph = engine.get_thought_graph()
for thought_id, thought in graph.thoughts.items():
print(f"{thought.premise}: {thought.confidence}")
def get_memory(self) -> ThreeLayerMemory
Get the three-layer memory system.
Returns:
ThreeLayerMemory: Memory system with episodic, pattern, and rule layersExample:
memory = engine.get_memory()
episodic = memory.get_episodic_memory()
patterns = memory.get_pattern_memory()
rules = memory.get_rule_memory()
Module: layers.interpreter
Class: Interpreter
Transform raw input into structured ProblemState.
def interpret(self, input: str) -> ProblemState
Transform raw input into structured problem state.
Parameters:
input (str): Raw user inputReturns:
ProblemState: Structured problem definitionExample:
from layers.interpreter import Interpreter
interpreter = Interpreter()
state = interpreter.interpret("How do I learn Python?")
print(state.goals)
print(state.constraints)
print(state.knowns)
Module: layers.generator
Class: Generator
Create multiple competing thought candidates.
def generate(self, problem_state: ProblemState) -> List[Thought]
Generate thought candidates from problem state.
Parameters:
problem_state (ProblemState): Structured problem definitionReturns:
List[Thought]: List of generated thought objectsExample:
from layers.generator import Generator
generator = Generator()
thoughts = generator.generate(problem_state)
for thought in thoughts:
print(f"{thought.premise}: {thought.confidence}")
Module: layers.deliberator
Class: Deliberator
Evaluate, test, and evolve thoughts.
def deliberate(self, thoughts: List[Thought]) -> List[Thought]
Evaluate and evolve a list of thoughts.
Parameters:
thoughts (List[Thought]): List of thoughts to deliberateReturns:
List[Thought]: Evolved and scored list of thoughtsExample:
from layers.deliberator import Deliberator
deliberator = Deliberator()
evolved_thoughts = deliberator.deliberate(thoughts)
for thought in evolved_thoughts:
print(f"Score: {thought.score}, Confidence: {thought.confidence}")
Module: layers.committer
Class: Committer
Select best thought and express output.
def commit(self, thoughts: List[Thought]) -> ProcessResult
Commit to the best thought and produce output.
Parameters:
thoughts (List[Thought]): List of thoughts to choose fromReturns:
ProcessResult: Final result with output and metadataExample:
from layers.committer import Committer
committer = Committer()
result = committer.commit(evolved_thoughts)
print(result.final_output)
Module: layers.meta
Class: MetaCognition
Govern the thinking process itself.
def should_continue(self, iteration: int, thoughts: List[Thought]) -> bool
Determine if cognitive process should continue.
Parameters:
iteration (int): Current iteration numberthoughts (List[Thought]): Current thoughtsReturns:
bool: True if should continue, False if should stopExample:
from layers.meta import MetaCognition
meta = MetaCognition({
"min_iterations": 3,
"max_iterations": 50,
"early_stop_confidence": 0.95
})
if meta.should_continue(iteration, thoughts):
# Continue deliberation
pass
else:
# Stop and commit
pass
Module: models.thought
Class: Thought
First-class thought object with state, history, and evaluative properties.
def __init__(
id: str,
premise: str,
confidence: float = 0.5,
parent_nodes: Optional[List[str]] = None
)
Parameters:
id (str): Unique identifierpremise (str): Core hypothesisconfidence (float): Initial confidence (0-1)parent_nodes (Optional[List[str]]): Parent thought IDsExample:
from models.thought import Thought
thought = Thought(
id="thought_1",
premise="Python is a versatile programming language",
confidence=0.7
)
update_confidence()
def update_confidence(self, new_confidence: float) -> None
add_weakness()
def add_weakness(self, weakness: str) -> None
record_test()
def record_test(self, test_result: Dict[str, Any]) -> None
revise()
def revise(self, new_premise: str) -> Thought
Module: models.thought
Class: ThoughtGraph
Graph of interconnected thoughts.
add_thought()
def add_thought(self, thought: Thought) -> None
get_thought()
def get_thought(self, thought_id: str) -> Optional[Thought]
get_related()
def get_related(self, thought_id: str) -> List[Thought]
find_path()
def find_path(self, from_id: str, to_id: str) -> List[Thought]
Module: models.state
Class: ProblemState
Structured problem definition.
def __init__(
goals: List[str],
constraints: List[str] = None,
knowns: List[str] = None,
unknowns: List[str] = None,
context: str = ""
)
Example:
from models.state import ProblemState
state = ProblemState(
goals=["Learn Python programming"],
constraints=["Limited time available"],
knowns=["Python is popular", "Python has good documentation"],
unknowns=["Best learning resources", "Time required"]
)
Module: core.memory
Class: ThreeLayerMemory
Three-layer memory system (Episodic, Pattern, Rule).
store_episodic()
def store_episodic(self, event: Dict[str, Any]) -> None
Store a raw event in episodic memory.
Parameters:
event (Dict): Event data to storeExample:
memory.store_episodic({
"type": "thought_generation",
"timestamp": datetime.now(),
"data": {"thought_premise": "..."}
})
extract_patterns()
def extract_patterns(self) -> List[Pattern]
Extract recurring patterns from episodic memory.
Returns:
List[Pattern]: List of extracted patternssynthesize_rules()
def synthesize_rules(self, patterns: List[Pattern]) -> List[Rule]
Convert patterns into actionable rules.
Parameters:
patterns (List[Pattern]): Patterns to convertReturns:
List[Rule]: List of synthesized rulesapply_rules()
def apply_rules(self, state: ProblemState) -> ProblemState
Apply learned rules to problem state.
Parameters:
state (ProblemState): Problem state to modifyReturns:
ProblemState: Modified problem stateget_episodic_memory()
def get_episodic_memory(self) -> List[Dict]
Retrieve episodic memory.
Returns:
List[Dict]: All episodic eventsget_pattern_memory()
def get_pattern_memory(self) -> List[Pattern]
Retrieve pattern memory.
Returns:
List[Pattern]: All extracted patternsget_rule_memory()
def get_rule_memory(self) -> List[Rule]
Retrieve rule memory.
Returns:
List[Rule]: All learned rulesModule: agent.agent
Class: Agent
Autonomous agent with goal-directed behavior.
def __init__(self, tool_registry: Optional[ToolRegistry] = None)
def run(self, goal: str) -> AgentResult
Execute agent with a goal.
Parameters:
goal (str): Goal to achieveReturns:
AgentResult: Result of agent executionExample:
from agent.agent import Agent
agent = Agent()
result = agent.run("Research the latest developments in AI")
print(result.final_state)
print(result.actions_taken)
Module: agent.planner
Class: Planner
Convert goals into actionable plans.
def create_plan(self, goal: str) -> Plan
Create execution plan from goal.
Parameters:
goal (str): Goal to plan forReturns:
Plan: Execution planModule: agent.executor
Class: Executor
Execute actions using tools.
def execute(self, plan: Plan) -> ActionResult
Execute a plan.
Parameters:
plan (Plan): Plan to executeReturns:
ActionResult: Result of executionModule: agent.observer
Class: Observer
Interpret and analyze execution results.
def observe(self, result: ActionResult) -> Observation
Observe and analyze execution results.
Parameters:
result (ActionResult): Result to observeReturns:
Observation: Analysis of resultsModule: learning.extractor
Class: PatternExtractor
Extract patterns from memory.
def extract_patterns(self, memory: List[Dict]) -> List[Pattern]
Extract patterns from episodic memory.
Parameters:
memory (List[Dict]): Episodic memory eventsReturns:
List[Pattern]: Extracted patternsModule: learning.synthesizer
Class: RuleSynthesizer
Convert patterns into rules.
def synthesize_rules(self, patterns: List[Pattern]) -> List[Rule]
Synthesize rules from patterns.
Parameters:
patterns (List[Pattern]): Patterns to convertReturns:
List[Rule]: Synthesized rulesModule: learning.updater
Class: KnowledgeUpdater
Inject learned knowledge into reasoning system.
def update_rules(self, rules: List[Rule]) -> None
Update rule memory with new rules.
Parameters:
rules (List[Rule]): Rules to addapply_rule()
def apply_rule(self, rule: Rule, state: ProblemState) -> ProblemState
Apply a rule to problem state.
Parameters:
rule (Rule): Rule to applystate (ProblemState): Problem state to modifyReturns:
ProblemState: Modified problem stateModule: dashboard.server
Class: DashboardServer
WebSocket server for real-time telemetry.
def __init__(self, host: str = "0.0.0.0", port: int = 8000)
def start(self) -> None
Start the WebSocket server.
Example:
from dashboard.server import DashboardServer
server = DashboardServer(port=8000)
server.start()
Module: dashboard.stream
Class: DashboardStreamer
Stream cognitive events to dashboard.
def stream_event(self, event: CognitiveEvent) -> None
Stream a cognitive event to dashboard.
Parameters:
event (CognitiveEvent): Event to streamExample:
from dashboard.stream import dashboard_streamer
from dashboard.events import ThoughtEvent
event = ThoughtEvent(
thought_id="thought_1",
premise="Example thought",
confidence=0.8
)
dashboard_streamer.stream_event(event)
Module: llm.client
Class: LLMClient
Single entry point for LLM interactions.
def __init__(self, provider: str = "openai")
Parameters:
provider (str): LLM provider ("openai" or "anthropic")def generate(self, prompt: str) -> str
Generate response from LLM.
Parameters:
prompt (str): Prompt to send to LLMReturns:
Example:
from llm.client import LLMClient
client = LLMClient(provider="openai")
response = client.generate("Explain quantum computing")
print(response)
def generate_with_context(self, prompt: str, context: Dict) -> str
Generate response with additional context.
Parameters:
prompt (str): Prompt to sendcontext (Dict): Additional contextReturns:
str: LLM responsedef stream_response(self, prompt: str) -> Iterator[str]
Stream response from LLM.
Parameters:
prompt (str): Prompt to sendReturns:
Iterator[str]: Stream of response chunksModule: tools.registry
Class: ToolRegistry
Manage and execute tools.
def register_tool(self, tool: Tool) -> None
Register a tool.
Parameters:
tool (Tool): Tool to registerdef call_tool(self, name: str, params: Dict) -> ToolResult
Call a registered tool.
Parameters:
name (str): Tool nameparams (Dict): Tool parametersReturns:
ToolResult: Result of tool executionExample:
from tools.registry import tool_registry
result = tool_registry.call_tool("web_search", {"query": "AI news"})
print(result.data)
Module: tools.web_search
Class: WebSearchTool
Web search tool for information retrieval.
def search(self, query: str) -> List[SearchResult]
Execute web search.
Parameters:
query (str): Search queryReturns:
List[SearchResult]: Search resultsExample:
from tools.web_search import WebSearchTool
tool = WebSearchTool()
results = tool.search("latest AI developments")
for result in results:
print(f"{result.title}: {result.url}")
Module: tools.code_exec
Class: CodeExecutionTool
Safe code execution tool.
def execute(self, code: str) -> ExecutionResult
Execute code safely.
Parameters:
code (str): Code to executeReturns:
ExecutionResult: Execution result with outputExample:
from tools.code_exec import CodeExecutionTool
tool = CodeExecutionTool()
result = tool.execute("print('Hello, World!')")
print(result.output)
Module: core.config
Class: Config
Configuration management.
def __init__(
min_iterations: int = 3,
max_iterations: int = 50,
early_stop_confidence: float = 0.95,
confidence_threshold: float = 0.7,
enable_dashboard: bool = True,
dashboard_port: int = 8000,
default_llm_provider: str = "openai"
)
@classmethod
def load_from_env(cls) -> Config
Load configuration from environment variables.
Returns:
Config: Configuration objectExample:
from core.config import Config
config = Config.load_from_env()
print(config.min_iterations)
print(config.default_llm_provider)
CognitiveEngineError
Base exception for cognitive engine errors.
MemoryError
Exception raised for memory-related errors.
ToolExecutionError
Exception raised when tool execution fails.
LLMError
Exception raised for LLM-related errors.
PatternExtractionError
Exception raised for pattern extraction failures.
RuleSynthesisError
Exception raised for rule synthesis failures.
from core.engine import CognitiveEngine
from core.engine import CognitiveEngineError
try:
engine = CognitiveEngine()
result = engine.process("Your query here")
except CognitiveEngineError as e:
print(f"Cognitive engine error: {e}")
except MemoryError as e:
print(f"Memory error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
class ProcessResult:
final_output: str
iteration_count: int
reasoning_trace: Optional[str]
thought_graph: ThoughtGraph
confidence: float
timestamp: datetime
class AgentResult:
final_state: Dict
actions_taken: List[Action]
observations: List[Observation]
goal_achieved: bool
execution_time: float
class ToolResult:
success: bool
data: Any
error: Optional[str]
execution_time: float
class SearchResult:
title: str
url: str
snippet: str
relevance: float
class ExecutionResult:
output: str
error: Optional[str]
execution_time: float
success: bool
from core.engine import CognitiveEngine
# Initialize engine
engine = CognitiveEngine()
# Process a query
result = engine.process("What is cognitive science?")
# Access results
print(result.final_output)
print(result.confidence)
print(result.iteration_count)
from core.engine import CognitiveEngine
from core.config import Config
# Create custom config
config = Config(
min_iterations=5,
max_iterations=20,
confidence_threshold=0.8
)
# Initialize with config
engine = CognitiveEngine(config)
result = engine.process("Explain quantum computing")
from core.engine import CognitiveEngine
engine = CognitiveEngine()
result = engine.process("Compare Python and JavaScript")
# Access thought graph
graph = engine.get_thought_graph()
for thought_id, thought in graph.thoughts.items():
print(f"Thought: {thought.premise}")
print(f"Confidence: {thought.confidence}")
print(f"Score: {thought.score}")
from core.engine import CognitiveEngine
engine = CognitiveEngine()
# Process multiple queries
engine.process("What is machine learning?")
engine.process("How do neural networks work?")
# Access memory
memory = engine.get_memory()
episodic = memory.get_episodic_memory()
patterns = memory.get_pattern_memory()
rules = memory.get_rule_memory()
print(f"Episodic entries: {len(episodic)}")
print(f"Patterns found: {len(patterns)}")
print(f"Rules learned: {len(rules)}")
from agent.agent import Agent
agent = Agent()
result = agent.run("Research the latest developments in AI")
print(f"Goal achieved: {result.goal_achieved}")
print(f"Actions taken: {len(result.actions_taken)}")
from tools.registry import tool_registry
# Call web search tool
result = tool_registry.call_tool("web_search", {
"query": "latest AI news"
})
# Call code execution tool
result = tool_registry.call_tool("code_exec", {
"code": "print(2 + 2)"
})