Skip to main content

Cognition Core

Core integration package for building AI agents with CrewAI, providing configuration management, memory systems, tool integration, and API capabilities.

Architecture

Cognition AI

cognition-core/
├── src/
│   └── cognition_core/
│       ├── api.py              # Core API implementation
│       ├── crew.py             # Enhanced CrewAI base
│       ├── agent.py            # Enhanced Agent class
│       ├── task.py             # Enhanced Task class
│       ├── llm.py              # Portkey LLM integration
│       ├── logger.py           # Logging system
│       ├── config.py           # Configuration management
│       ├── memory/             # Memory implementations
│       │   ├── entity.py       # Entity memory with Chroma
│       │   ├── long_term.py    # PostgreSQL long-term memory
│       │   ├── short_term.py   # Chroma short-term memory
│       │   ├── storage.py      # ChromaDB storage implementation
│       │   └── mem_svc.py      # Memory service orchestration
│       └── tools/              # Tool management
│           ├── custom_tool.py  # Base for custom tools
│           └── tool_svc.py     # Dynamic tool service

Core Features

1. Enhanced Crew Base

  • Automatic API capability through @CognitionCoreCrewBase decorator
  • Integrated tool service management
  • Memory system initialization
  • Configuration management
  • Portkey LLM integration

2. Memory Systems

  • Short-term Memory: ChromaDB-based implementation
  • Long-term Memory: PostgreSQL-based storage
  • Entity Memory: Relationship tracking with ChromaDB
  • Configurable storage backends
  • Embedder configuration support

3. Tool Integration

  • Dynamic tool loading from HTTP endpoints
  • Tool service with caching
  • Async tool operations
  • Tool refresh capability
  • Structured tool definitions with Pydantic

4. API Integration

  • Built-in FastAPI implementation
  • Async task processing
  • Health check endpoints
  • Task status tracking
  • Background task execution

5. Configuration Management

  • Hot-reloading YAML configuration
  • Environment variable integration
  • Configurable paths
  • Fallback to CrewAI defaults

Environment Variables

Required:

  • PORTKEY_API_KEY: API key for Portkey LLM routing
  • PORTKEY_VIRTUAL_KEY: Virtual key for Portkey
  • COGNITION_CONFIG_DIR: Path to your configuration directory (e.g., "/home/user/.cognition/cognition-config-demo/config")

Optional:

  • COGNITION_CONFIG_SOURCE: Git repository URL to clone configuration (e.g., "git@github.com:user/config-repo.git")
    • If set, will clone the repository to ~/.cognition
    • COGNITION_CONFIG_DIR should then point to the config directory within the cloned repo
  • CONFIG_RELOAD_TIMEOUT: Config reload timeout (default: 0.1)
  • LONG_TERM_DB_PASSWORD: PostgreSQL database password
  • CHROMA_PASSWORD: ChromaDB password
  • APP_LOG_LEVEL: Logging level (default: INFO)

Note: When using remote configuration:

  1. The repository will be cloned to ~/.cognition
  2. Set COGNITION_CONFIG_DIR to point to the config directory within the cloned repository
  3. Configuration is managed through a singleton pattern to prevent multiple clones/reloads

Usage Example

from cognition_core import CognitionCoreCrewBase
from crewai import Agent, Task

@CognitionCoreCrewBase
class YourCrew:
    @agent
    def researcher(self) -> Agent:
        return self.get_cognition_agent(
            config=self.agents_config["researcher"],
            llm=self.init_portkey_llm(
                model="gpt-4",
                portkey_config=self.portkey_config
            )
        )

    @task
    def research_task(self) -> Task:
        return CognitionTask(
            config=self.tasks_config["research"],
            tools=["calculator", "search"]
        )

    @crew
    def crew(self) -> Crew:
        return CognitionCrew(
            agents=self.agents,
            tasks=self.tasks,
            process=Process.sequential,
            memory=True,
            tool_service=self.tool_service
        )

# Access API
app = YourCrew().api

Configuration Files

Memory Configuration (memory.yaml)

short_term_memory:
  enabled: true
  external: true
  host: "localhost"
  port: 8000
  collection_name: "short_term"

long_term_memory:
  enabled: true
  external: true
  connection_string: "postgresql://user:${LONG_TERM_DB_PASSWORD}@localhost:5432/db"

entity_memory:
  enabled: true
  external: true
  host: "localhost"
  port: 8000
  collection_name: "entities"

embedder:
  provider: "ollama"
  config:
    model: "nomic-embed-text"
    vector_dimension: 384

Tool Configuration (tools.yaml)

tool_services:
  - name: "primary_service"
    enabled: true
    base_url: "http://localhost:8080/api/v1"
    endpoints:
      - path: "/tools"
        method: "GET"

settings:
  cache:
    enabled: true
    ttl: 3600
  validation:
    response_timeout: 30

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request with tests

License

MIT

Metadata

Release files for cognition-core 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cognition-core 0.6.0
File Size Uploaded
cognition_core-0.6.0.tar.gz 122.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cognition-core 0.6.0
File Interpreter ABI Platform
cognition_core-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 148.9 kB

Release files / cognition_core-0.6.0.tar.gz

Download URL cognition_core-0.6.0.tar.gz
Size 122.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1d79a47b739352a60a22880e1364063ac45fab80a8742b9d781f264c2c68f476
BLAKE2b-256 checksum
How to use checksums
29f4407f09d2c59c5ecb6f23dddca5925e38974b9e4e66b8a74640fbf8c6030a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release files / cognition_core-0.6.0-py3-none-any.whl

Download URL cognition_core-0.6.0-py3-none-any.whl
Size 26.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d31bd5b2e50cca1dbc259d42650fd97a629cee0dce13debc3a89f958f02c401
BLAKE2b-256 checksum
How to use checksums
daacc6fe10af5952a540a51576bc7433da5d85b0a79631bdedfa4cc3e33bab8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page