Skip to main content

Embeddable agent execution kernel — LLM loop, hooks, events, tools, dynamic sub-agents.

Project description

power-loop

Documentation | 中文文档 | Examples | Changelog

Embeddable, stateful agent execution for Python.

power-loop gives application code one small interface, StatefulAgentLoop, and handles the repetitive agent runtime work around it: multi-turn LLM loops, tool calls, hooks, events, context compaction, sub-agents, retry/cancel, structured output, memory, and SQLite-backed session persistence.

It is a library, not a service or a full application framework. You keep ownership of product logic, HTTP APIs, auth, queues, RAG, UI, and deployment.

Install

pip install power-loop

For local development:

git clone https://github.com/PL-play/power-loop.git
cd power-loop
pip install -e ".[dev]"

Python 3.10+ is required.

Quick Example

import asyncio

from power_loop import AgentLoopConfig, StatefulAgentLoop, create_llm_service_from_env


async def main() -> None:
    llm = create_llm_service_from_env()
    loop = StatefulAgentLoop(
        llm=llm,
        db_path="./power_loop_sessions.db",
        config=AgentLoopConfig(
            system_prompt="You are a concise assistant.",
            max_rounds=4,
        ),
    )

    sid = loop.new_session(metadata={"user_id": "demo"})
    first = await loop.send("My favorite color is teal.", session_id=sid)
    second = await loop.send("What is my favorite color?", session_id=sid)

    print(second.final_text)


asyncio.run(main())

Configure any OpenAI-compatible endpoint with environment variables:

POWER_LOOP_BASE_URL=https://api.openai.com/v1
POWER_LOOP_API_KEY=sk-...
POWER_LOOP_MODEL=gpt-4o-mini

See Getting Started for the complete first run.

What It Provides

Capability Where to read more
Stateful sessions and cross-process resume Sessions
Tool calling with JSON Schema validation Tools
Lifecycle hooks for control flow Hooks
Typed events for streaming, audit, and metrics Events
Context compaction Compaction
Sub-agents with AgentSpec Sub-agents
Retry, timeout, and cancellation Retry & Cancel
Structured JSON output Structured Output
Pluggable cross-session memory Memory
Provider configuration Providers

Public API

Stable imports are re-exported from power_loop:

from power_loop import (
    AgentLoopConfig,
    StatefulAgentLoop,
    StatefulResult,
    ToolDefinition,
    ToolRegistry,
)

The stability tiers are:

Tier Meaning
Stable Backward compatible across minor releases. Listed in power_loop.STABLE_API.
Provisional Available from the top-level package during 0.x, but may change.
Internal Submodule imports such as power_loop.core.*; no compatibility promise.

See the API reference for the current surface.

Examples

The examples/ directory is ordered from minimal usage to full chatbot composition:

python examples/00_hello_world.py
python examples/02_tool_calling.py
python examples/19_full_chatbot.py

The full list is in examples/README.md.

Development

pip install -e ".[dev]"
ruff check .
pytest -q --no-real

Real LLM examples/tests use POWER_LOOP_* or the legacy OPENAI_COMPAT_* variables.

Project Links

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

power_loop-0.5.0.tar.gz (127.2 kB view details)

Uploaded Source

Built Distribution

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

power_loop-0.5.0-py3-none-any.whl (147.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: power_loop-0.5.0.tar.gz
  • Upload date:
  • Size: 127.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for power_loop-0.5.0.tar.gz
Algorithm Hash digest
SHA256 4223ea7faf91f688e51b8f89976aafa4230330bf1e81f8871d9d47a7a775522a
MD5 44b5e4473418b7dfaccfa2d35f005e45
BLAKE2b-256 790a75067b6f411438e3d74177e4a69b4f8a53e416f2028cda3a5cd7cf436b33

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_loop-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 147.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for power_loop-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d52a805b575a364600e0286a893efcf63e6637433bd16dfa6ae0d5a50ec595d5
MD5 617fe7af593d94d4da5fe26f5e580a48
BLAKE2b-256 16be8c6db0747fe974e081de942e0e9528050b58f0e592b86fe4a3bf987698e6

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