Official Cogspace SDK — add a knowledge layer to any AI agent
Project description
cogspace
Official Python SDK for Cogspace — persistent knowledge layer for AI agents.
Install
pip install cogspace
Quickstart
import asyncio
import os
from cogspace import AsyncCogspace
# Set your API key (or pass api_key= directly)
os.environ["COGSPACE_API_KEY"] = "cs-..."
async def main():
cog = AsyncCogspace()
space = await cog.space("my-agent")
# See what exists
files = await space.list("expertise")
print(f"Files: {files.file_count}")
# Add knowledge
await space.add(
path="expertise/retry.md",
content="# Retry Patterns\nUse exponential backoff with jitter.",
layer="expertise",
topic="retry-patterns",
confidence=0.95,
)
# Search
results = await space.search("retry logic", limit=5)
for item in results.results:
print(f"{item.path}: {item.score:.2f}")
# Retrieve a file
file = await space.retrieve("expertise/retry.md")
print(file.content)
# Delete
await space.forget("expertise/retry.md")
await cog.aclose()
asyncio.run(main())
Sync client
from cogspace import Cogspace
with Cogspace() as cog:
space = cog.space("my-agent")
files = space.list("expertise")
results = space.search("retry logic", limit=5)
space.add(
path="expertise/retry.md",
content="# Retry Patterns\n...",
layer="expertise",
topic="retry-patterns",
)
space.forget("expertise/retry.md")
API Reference
Cogspace(api_key, base_url, timeout, max_retries)
Reads COGSPACE_API_KEY from environment if api_key not provided.
| Method | Description |
|---|---|
cog.space(name_or_id) |
Get a space client by name or ID |
cog.list_spaces() |
List all your spaces |
cog.create_space(name) |
Create a new space |
SpaceClient
| Method | Args | Description |
|---|---|---|
space.list(folder) |
folder="" |
List files in folder |
space.retrieve(path) |
path |
Get one file with content + metadata |
space.search(query, limit, layer) |
limit=10, layer=None |
Search all layers |
space.add(path, content, layer, topic, confidence, relates_to) |
see below | Add/update knowledge |
space.forget(path) |
path |
Delete from all layers |
add() parameters
| Param | Type | Required | Description |
|---|---|---|---|
path |
str | yes | File path (e.g. "expertise/retry.md") |
content |
str | yes | Markdown content |
layer |
str | yes | "expertise", "memory", or "root" |
topic |
str | yes | Category/topic |
confidence |
float | no | 0.0-1.0, default 0.9 |
relates_to |
list[str] | no | Related file names |
Layers
| Layer | Use for |
|---|---|
expertise |
Knowledge, patterns, guides, reference material |
memory |
Agent memory, user preferences, session notes |
root |
General knowledge that doesn't fit elsewhere |
Limits
search(limit=...)— max 100 results per callforget()— single file per call
Errors
from cogspace.exceptions import AuthError, NotFoundError, RateLimitError, LimitExceededError
try:
results = await space.search("query", limit=200)
except LimitExceededError:
print("Limit must be <= 100")
except AuthError:
print("Invalid API key")
except NotFoundError:
print("Space not found")
Get an API key
Sign in at platform.cogspace.ai → Settings → API keys → Create key.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cogspace-0.2.1.tar.gz
(8.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
cogspace-0.2.1-py3-none-any.whl
(10.8 kB
view details)
File details
Details for the file cogspace-0.2.1.tar.gz.
File metadata
- Download URL: cogspace-0.2.1.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c0310b7260e8f1affb46c0e316f0de151dd4d904b69d83ed1e5501b2468eb45
|
|
| MD5 |
f4d2c49cff4ff84547d806e2058cb705
|
|
| BLAKE2b-256 |
e994461f94cab5ee77b46a1156b6a0169efd96231d3cfc290673acff975d3208
|
File details
Details for the file cogspace-0.2.1-py3-none-any.whl.
File metadata
- Download URL: cogspace-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfa7cd271d2579b9da5f9dc0f2c85c28206cb4e6d9513c04d0cc6f4e6e8424af
|
|
| MD5 |
c5015e341a21ee4eba1609efb867b257
|
|
| BLAKE2b-256 |
f5d8c898afa82a5cbdbfffec7654670b4c5ecc975a1b272f3971a9d6b257e34a
|