Skip to main content

Model-transport layer for the Cogno cognitive pipeline — LLM + embedding backend protocols, Ollama + cloud backends, a single-backend factory, and a resilient fallback chain

Project description

cogno-synapse

Model-transport layer for the Cogno cognitive pipeline — LLM + embedding backend protocols, Ollama + cloud backends, a single-backend factory, and a resilient fallback chain.

Named for the synapse: the junction that carries the signal between neurons. Where cogno-anima is the mind and cogno-engram is the memory, cogno-synapse is the channel the mind speaks to language/embedding models through.

Status: alpha — extracted from cogno-anima's llm/ package; unit suite (mocked SDKs) in place.

Protocol first, implementation optional

The light, stable contract everyone shares is a set of structurally-typed Protocols (no inheritance required):

  • LLMBackendasync generate(system, prompt) -> (text, tokens_in, tokens_out) + a model attr.
  • ToolCallingBackend (extends LLMBackend) — adds chat_with_tools(...) + supports_native_tools() for native function calling. Separate and optional, so a text-only backend (a stub, a distilled student) satisfies only LLMBackend.
  • Embedderasync embed(text) -> list[float], async similarity(a, b) -> float.

The heavy concrete cloud backends are optional extras (lazy-imported SDKs) — depend on the protocol, install only the providers you use:

pip install cogno-synapse                       # protocols + Ollama + OpenAI-compatible HTTP + fallback (httpx only)
pip install "cogno-synapse[openai]"             # + OpenAI SDK
pip install "cogno-synapse[anthropic|groq|gemini|bedrock]"
pip install "cogno-synapse[llm]"                # all cloud SDKs

Backends

OllamaBackend/OllamaEmbedder (local, think=false by default so reasoning models still return direct JSON), plus OpenAIBackend, AnthropicBackend, GroqBackend, GeminiBackend, BedrockBackend — each implements LLMBackend + ToolCallingBackend. OpenAI-compatible providers (DeepSeek, Moonshot, xAI/Grok, OpenRouter, Together, Fireworks) reuse OpenAIBackend via base_url; create_backend("provider:model") instantiates one by string. Backends raise on transport/auth failure (InvalidAPIKeyError for 401/403) rather than degrading silently.

CachingEmbedder wraps any Embedder with a bounded LRU + token accounting (EmbeddingUsage). parse_tool_calls_from_text reads <TOOL_CALL> tags for the text-fallback function-calling path (and rescues FC leaks).

Resilient fallback — over cogno-homeo

FallbackBackend tries an ordered chain, first success wins, last error propagates. The loop runs on cogno-homeo's resilient_call, so you can opt into a circuit breaker, retry/backoff, and a metrics seam — with none supplied it behaves like the historical "try each once" chain:

from cogno_synapse import FallbackBackend, create_backend
from cogno_homeo import CircuitBreaker, RetryPolicy

chain = FallbackBackend(
    [create_backend("openai:gpt-4o-mini"), create_backend("groq:llama-3.1-8b-instant")],
    breaker=CircuitBreaker(), policy=RetryPolicy(max_retries=2),   # optional
)
text, tin, tout = await chain.generate(system, prompt)

Scope

This library is transport only — it produces raw token counts but does not price them (the host does), and it carries no business model-ladder/_FALLBACK_MATRIX (also host). Resilience is delegated to cogno-homeo; cognition lives in cogno-anima.

The Cogno ecosystem

cogno-synapse is one organ of Cogno — a family of small, composable, Apache-2.0 libraries that together form a complete conversational-agent platform. Each library owns a single concern and stays infra-agnostic; a host assembles them into a running agent:

The Cogno ecosystem

The open-source libraries are the organs; the host is the body that joins them. Our reference host — cogno-host, with its cogno-ui dashboard — is the private product layer, but it holds no special powers: everything it does rides on the public seams documented in each library's docs/HOST_INTEGRATION.md, so you can assemble a body of your own.

Test

pip install -e ".[dev]"      # unit tests mock every SDK — no cloud keys needed
pytest tests/unit -q

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

cogno_synapse-0.1.1.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

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

cogno_synapse-0.1.1-py3-none-any.whl (42.3 kB view details)

Uploaded Python 3

File details

Details for the file cogno_synapse-0.1.1.tar.gz.

File metadata

  • Download URL: cogno_synapse-0.1.1.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for cogno_synapse-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dfbdb1e3c472238986012a9593ccf03f2cc9ebf0a24119e3a2e73d9fafe7e932
MD5 4891fd7a3f977194edaab2ec57a79ba7
BLAKE2b-256 c704b9bb06cabd7df98cd9251bc3b3eaad690dfabf536d53a1ec816a26ff1973

See more details on using hashes here.

Provenance

The following attestation bundles were made for cogno_synapse-0.1.1.tar.gz:

Publisher: release.yml on sudoers-ai/cogno-synapse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cogno_synapse-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cogno_synapse-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 42.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for cogno_synapse-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0809a95040a4c7649e9099ea18ca35b78d5eb14eb5b7b8f2eb5f1ab55184ada2
MD5 747b79420f794eb016e17675cad82012
BLAKE2b-256 f78f943e6cc4432d51a805f300692c97acef3f9ebfccfea36f81e6f7840b0247

See more details on using hashes here.

Provenance

The following attestation bundles were made for cogno_synapse-0.1.1-py3-none-any.whl:

Publisher: release.yml on sudoers-ai/cogno-synapse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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