Skip to main content

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

Project description

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

Optional:

  • COGNITION_CONFIG_DIR: Configuration directory path
  • 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)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cognition_core-0.5.0.tar.gz (118.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cognition_core-0.5.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file cognition_core-0.5.0.tar.gz.

File metadata

  • Download URL: cognition_core-0.5.0.tar.gz
  • Upload date:
  • Size: 118.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for cognition_core-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e8c6afdbdd656708562db84b68c70cd93f6ee8a1d6bf5f2e077a4afb2419bba5
MD5 88b50bc11e0aecf240327de20e2b9821
BLAKE2b-256 042b160db96130f2ee094919a8e1fb2b38792ebd827d9df2038af06991af6ac8

See more details on using hashes here.

File details

Details for the file cognition_core-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: cognition_core-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for cognition_core-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 195da522e80ad768cb9aa778f7707833f978dee29811f3e34b5014dfa4d67f75
MD5 d7da4f0d2329fa14655e1633b9397d96
BLAKE2b-256 e5bc338ce226820cfab1b15c31af1ced56acc89f6d7d6b45f6f4e9d77f25de57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page