Core primitives for building AI agent loops
Project description
isotopes-core
Core primitives for building AI agent loops. Provides the engine that powers isotopes — a turn-based execution loop, LLM provider abstraction, middleware system, typed event streaming, context management, and a tool framework.
Installation
From PyPI
# uv
uv add isotopes-core
uv add 'isotopes-core[openai]'
uv add 'isotopes-core[anthropic]'
uv add 'isotopes-core[all]'
# pip
pip install isotopes-core # core only (pydantic)
pip install isotopes-core[openai] # + OpenAI provider
pip install isotopes-core[anthropic] # + Anthropic provider
pip install isotopes-core[all] # all providers + tiktoken
From Source (monorepo)
# Sync just isotopes-core into the workspace environment
uv sync --package isotopes-core
# Include optional provider extras
uv sync --package isotopes-core --extra openai
uv sync --package isotopes-core --extra anthropic
uv sync --package isotopes-core --extra all
API Overview
Agent
The Agent class is the main entry point — it wraps the agent loop with state management, streaming, steering, follow-ups, and abort support.
from isotopes_core import Agent
agent = Agent(
provider=my_provider,
system_prompt="You are a helpful assistant.",
tools=[my_tool],
max_turns=10,
)
async for event in agent.prompt("Hello!"):
if event.type == "message_update":
print(event.delta, end="")
# Inject steering mid-turn, queue follow-ups, or abort
agent.steer("Focus on error handling.")
agent.follow_up("Now write tests.")
agent.abort()
Providers
Providers implement the Provider protocol and stream LLM responses as typed events.
from isotopes_core.providers.proxy import ProxyProvider
from isotopes_core.providers.openai import OpenAIProvider
from isotopes_core.providers.anthropic import AnthropicProvider
# OpenAI-compatible proxy (LiteLLM, Ollama, vLLM, Azure, etc.)
proxy = ProxyProvider(model="gpt-4o", base_url="http://localhost:4141/v1")
# Direct OpenAI
openai = OpenAIProvider(model="gpt-4o", api_key="sk-...")
# Direct Anthropic (supports extended thinking)
anthropic = AnthropicProvider(model="claude-opus-4.6", api_key="sk-ant-...")
A RouterProvider adds multi-provider routing with automatic fallback and circuit breaker.
@auto_tool Decorator
Define tools from plain async functions. The JSON schema is auto-generated from type hints and docstring.
from isotopes_core import auto_tool
@auto_tool
async def grep(pattern: str, path: str = ".", max_results: int = 50) -> str:
"""Search file contents with a regex pattern.
Args:
pattern: The regex pattern to search for.
path: Directory to search in.
max_results: Maximum number of matches to return.
"""
...
Supported types: str, int, float, bool, list[T], T | None. Parameters without defaults become required.
Middleware
Composable middleware chain that intercepts events flowing through the agent loop.
from isotopes_core import LoggingMiddleware, TokenTrackingMiddleware, EventFilterMiddleware
agent = Agent(
provider=my_provider,
middleware=[
LoggingMiddleware(log_level="normal"),
TokenTrackingMiddleware(),
EventFilterMiddleware(exclude={"message_update"}),
],
)
Context Management
- FileTracker — tracks file read/write operations across a session
- SlidingWindowStrategy — drops oldest messages when context exceeds a threshold
- SummarizationStrategy — summarizes old messages using the LLM
- SelectivePruningStrategy — removes specific message types
- pin_message / unpin_message — protect messages from pruning
- count_tokens / estimate_context_usage — token counting with optional tiktoken
Loop Detection
The agent loop detects repetitive tool-call patterns by hashing consecutive tool names and arguments. When a loop is detected, a LoopDetectedEvent is emitted to prevent runaway execution.
License
MIT
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
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
File details
Details for the file isotopes_core-0.0.1.tar.gz.
File metadata
- Download URL: isotopes_core-0.0.1.tar.gz
- Upload date:
- Size: 111.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86d69e4db2061031ec15284fba6114d78b9e8c0393e3c27766aeab5657d9e58d
|
|
| MD5 |
548ac84d6609ab17cb2573de5343e788
|
|
| BLAKE2b-256 |
ffb9c637fda89971c410d49e10da352dc746c13b32849e50b908e390de1e7d8d
|
Provenance
The following attestation bundles were made for isotopes_core-0.0.1.tar.gz:
Publisher:
publish-core.yml on GhostComplex/isotopes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isotopes_core-0.0.1.tar.gz -
Subject digest:
86d69e4db2061031ec15284fba6114d78b9e8c0393e3c27766aeab5657d9e58d - Sigstore transparency entry: 1191434356
- Sigstore integration time:
-
Permalink:
GhostComplex/isotopes@b2e60eb945ec708bce79f87ac0a3b6552bd8541e -
Branch / Tag:
refs/tags/core-v0.0.1 - Owner: https://github.com/GhostComplex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-core.yml@b2e60eb945ec708bce79f87ac0a3b6552bd8541e -
Trigger Event:
release
-
Statement type:
File details
Details for the file isotopes_core-0.0.1-py3-none-any.whl.
File metadata
- Download URL: isotopes_core-0.0.1-py3-none-any.whl
- Upload date:
- Size: 51.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a2b9ddb1f3dcdaf5f8d00b886b3b63c668ed97601fb2acf2ce420be73299eaf
|
|
| MD5 |
bcbfa36dc30141f33e5edecdb2b88d22
|
|
| BLAKE2b-256 |
332e4bf234ccfc9f257806a36c28f90a7200d9c434fc6e87369db98ceb07d424
|
Provenance
The following attestation bundles were made for isotopes_core-0.0.1-py3-none-any.whl:
Publisher:
publish-core.yml on GhostComplex/isotopes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isotopes_core-0.0.1-py3-none-any.whl -
Subject digest:
9a2b9ddb1f3dcdaf5f8d00b886b3b63c668ed97601fb2acf2ce420be73299eaf - Sigstore transparency entry: 1191434360
- Sigstore integration time:
-
Permalink:
GhostComplex/isotopes@b2e60eb945ec708bce79f87ac0a3b6552bd8541e -
Branch / Tag:
refs/tags/core-v0.0.1 - Owner: https://github.com/GhostComplex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-core.yml@b2e60eb945ec708bce79f87ac0a3b6552bd8541e -
Trigger Event:
release
-
Statement type: