Getting Started

This guide will help you get started with CortexFlow.

Basic Usage

Here’s a simple example of how to use CortexFlow:

from cortexflow import CortexFlowManager, CortexFlowConfig, MemoryConfig, LLMConfig

# Configure with custom settings (nested config)
config = CortexFlowConfig(
    memory=MemoryConfig(active_token_limit=2048, working_token_limit=4096, archive_token_limit=8192),
    llm=LLMConfig(backend="ollama", default_model="llama3"),
)

# Create the context manager
context_manager = CortexFlowManager(config)

# Add messages to the context
context_manager.add_message("system", "You are a helpful AI assistant.")
context_manager.add_message("user", "What is the capital of France?")

# Generate a response
response = context_manager.generate_response()
print(f"Assistant: {response}")

# Explicitly store important information
context_manager.remember_knowledge("The user's name is Alice and she lives in Boston.")

# Clean up when done
context_manager.close()

Using the ConfigBuilder

CortexFlow also supports a fluent builder pattern for configuration:

from cortexflow import CortexFlowManager, ConfigBuilder

config = (ConfigBuilder()
    .with_memory(active_token_limit=2000, working_token_limit=4000, archive_token_limit=6000)
    .with_llm(default_model="llama3")
    .build())

manager = CortexFlowManager(config)

Advanced Features

Chain of Agents

CortexFlow includes a Chain of Agents framework that breaks down complex reasoning into specialized roles:

from cortexflow import CortexFlowManager, ConfigBuilder

# Enable Chain of Agents via the builder
config = (ConfigBuilder()
    .with_agents(use_chain_of_agents=True, chain_complexity_threshold=5)
    .with_llm(default_model="llama3")
    .build())

# Create the manager with this configuration
manager = CortexFlowManager(config)

# Add a complex query
manager.add_message("user", "What connection exists between quantum physics and consciousness?")

# Generate response (automatically uses Chain of Agents for complex queries)
response = manager.generate_response()

See the Configuration guide for more details on all available options.