Skip to main content

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


Download files

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

Source Distribution

isotopes_core-0.0.1.tar.gz (111.4 kB view details)

Uploaded Source

Built Distribution

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

isotopes_core-0.0.1-py3-none-any.whl (51.7 kB view details)

Uploaded Python 3

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

Hashes for isotopes_core-0.0.1.tar.gz
Algorithm Hash digest
SHA256 86d69e4db2061031ec15284fba6114d78b9e8c0393e3c27766aeab5657d9e58d
MD5 548ac84d6609ab17cb2573de5343e788
BLAKE2b-256 ffb9c637fda89971c410d49e10da352dc746c13b32849e50b908e390de1e7d8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for isotopes_core-0.0.1.tar.gz:

Publisher: publish-core.yml on GhostComplex/isotopes

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

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

Hashes for isotopes_core-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a2b9ddb1f3dcdaf5f8d00b886b3b63c668ed97601fb2acf2ce420be73299eaf
MD5 bcbfa36dc30141f33e5edecdb2b88d22
BLAKE2b-256 332e4bf234ccfc9f257806a36c28f90a7200d9c434fc6e87369db98ceb07d424

See more details on using hashes here.

Provenance

The following attestation bundles were made for isotopes_core-0.0.1-py3-none-any.whl:

Publisher: publish-core.yml on GhostComplex/isotopes

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