Python agent runtime framework — context management, multi-agent orchestration, and self-improvement for autonomous AI agents
Project description
Loom
Build stateful agents with context control, safety boundaries, and extensible runtime capabilities.
English | 中文
Wiki | Quick Start | PyPI
Loom exposes one public API centered on Agent. You configure an agent once, then use run(), stream(), and session() to build applications with multi-step execution, tools, heartbeat monitoring, safety rules, and session-scoped state.
Quick Start
pip install loom-agent
export ANTHROPIC_API_KEY=sk-ant-...
import asyncio
from loom import (
AgentConfig,
GenerationConfig,
ModelRef,
RunContext,
SessionConfig,
create_agent,
tool,
)
from loom.config import (
MemoryBackend,
MemoryConfig,
PolicyConfig,
PolicyContext,
RuntimeConfig,
RuntimeFeatures,
RuntimeLimits,
ToolAccessPolicy,
ToolPolicy,
ToolRateLimitPolicy,
)
@tool(description="Search documentation", read_only=True)
async def search_docs(query: str) -> str:
return f"Results for: {query}"
async def main():
agent = create_agent(
AgentConfig(
model=ModelRef.anthropic("claude-sonnet-4"),
instructions="You are a concise coding assistant",
tools=[search_docs],
policy=PolicyConfig(
tools=ToolPolicy(
access=ToolAccessPolicy(
allow=["search_docs"],
read_only_only=True,
),
rate_limits=ToolRateLimitPolicy(max_calls_per_minute=60),
),
context=PolicyContext.named("repo"),
),
memory=MemoryConfig(backend=MemoryBackend.in_memory()),
generation=GenerationConfig(max_output_tokens=512),
runtime=RuntimeConfig(
limits=RuntimeLimits(max_iterations=32),
features=RuntimeFeatures(enable_safety=True),
),
)
)
result = await agent.run("Summarize this repository")
print(result.output)
asyncio.run(main())
Import rule:
- Use
from loom import ...for the primary application path. - Use
from loom.config import ...for advanced configuration objects. - Use
from loom.runtime import ...for runtime states, runs, and sessions when you need them directly.
Sessions
Use session() when the application needs continuity across runs.
session = agent.session(SessionConfig(id="demo-user"))
first = await session.run("List three qualities of a good API")
second = await session.run(
"Summarize the previous answer in one sentence",
context=RunContext(inputs={"previous_answer": first.output}),
)
print(second.output)
Knowledge Evidence
Use KnowledgeQuery to resolve stable evidence, then attach it to one run through RunContext.
from loom import KnowledgeQuery
knowledge = agent.resolve_knowledge(
KnowledgeQuery(
text="What are the production deployment rules?",
goal="Summarize deployment policy",
top_k=3,
)
)
result = await agent.run(
"Summarize deployment policy",
context=RunContext(knowledge=knowledge),
)
Streaming, Events, and Artifacts
run = agent.session(SessionConfig(id="stream-demo")).start("Inspect the project layout")
async for event in run.events():
print(event.type, event.payload)
result = await run.wait()
artifacts = await run.artifacts()
Extensible Configuration
Loom keeps configuration extensible through stable config objects on the public API:
AgentConfig: top-level stable entry for one agentknowledge: reusable knowledge sources for evidence and retrievalpolicy: tool access controls, context-specific governance, rate limitsmemory: session-level memory optionsheartbeat: watch sources, interval, entropy thresholdsafety_rules: veto rules for dangerous operationsruntime: engine-level limits and features
Example:
agent = create_agent(
AgentConfig(
model=ModelRef.anthropic("claude-sonnet-4"),
instructions="You are a deployment assistant",
knowledge=[
KnowledgeSource.inline(
"deployment-docs",
[
KnowledgeDocument(content="Staging deploys are automatic.", title="Staging"),
KnowledgeDocument(content="Production deploys require approval.", title="Production"),
],
description="Internal deployment notes",
)
],
policy=PolicyConfig(
context=PolicyContext.named("deployment"),
tools=ToolPolicy(
access=ToolAccessPolicy(allow=["deploy"]),
rate_limits=ToolRateLimitPolicy(max_calls_per_minute=10),
),
),
memory=MemoryConfig(backend=MemoryBackend.in_memory()),
heartbeat=HeartbeatConfig(
interval=5.0,
interrupt_policy=HeartbeatInterruptPolicy(),
watch_sources=[
WatchConfig.filesystem(
paths=["./src"],
method=FilesystemWatchMethod.HASH,
),
WatchConfig.resource(
thresholds=ResourceThresholds(cpu_pct=80.0),
),
],
),
runtime=RuntimeConfig(
limits=RuntimeLimits(max_iterations=24, max_context_tokens=120000),
),
safety_rules=[
SafetyRule.when_argument_equals(
name="no_prod_deploy",
reason="Production deployment is blocked",
tool_name="deploy",
argument="env",
value="production",
)
],
)
)
Architecture
loom/agent.py ← Public agent API
loom/runtime/ ← Sessions, runs, loop, heartbeat, engine
loom/context/ ← Context partitions, compression, renewal, dashboard
loom/memory/ ← Session, working, semantic, persistent memory
loom/tools/ ← Tool registry, executor, governance pipeline
loom/orchestration/ ← Task planning and multi-agent coordination
loom/safety/ ← Permissions, hooks, veto authority
loom/ecosystem/ ← Skills, plugins, MCP bridge, activation
loom/evolution/ ← Self-improvement strategies
loom/providers/ ← Anthropic, OpenAI, Gemini, Qwen, Ollama
Why Loom
- Structured Reason → Act → Observe → Δ execution loop
- Context pressure management and renewal
- Background heartbeat sensing
- Tool governance and veto-based safety boundaries
- Session-scoped runs, events, and artifacts
- Extensible skills, plugins, and MCP integrations
License
Apache 2.0 with Commons Clause. See LICENSE.
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 loom_agent-0.7.2.tar.gz.
File metadata
- Download URL: loom_agent-0.7.2.tar.gz
- Upload date:
- Size: 103.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d8ae99b32ae1d0ed4697aa6377dcf46652759ce6469fc62f71f667a4b771248
|
|
| MD5 |
03a0f70ba23c79536d098503de1a3714
|
|
| BLAKE2b-256 |
58608d536a9e2b7f834a8740060c54960ad1bd9c9acbdfa68611df485e664146
|
File details
Details for the file loom_agent-0.7.2-py3-none-any.whl.
File metadata
- Download URL: loom_agent-0.7.2-py3-none-any.whl
- Upload date:
- Size: 139.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40b43b638637ed8de68ff111e4ca2d0bac13e5a09ca30f6b42ae68f3483590a5
|
|
| MD5 |
24673c4698be8efe2ce95bd6a3089d75
|
|
| BLAKE2b-256 |
b07606d10abc9902d2c4ac88a97cd4f682c21908160640a1465321b7e064ea2b
|