Skip to main content

Run a single exoclaw agent turn as a library call — no bus, no channels, no persistence

Project description

exoclaw-turn

Run a single exoclaw agent turn as a library call — no bus, no channels, no persistence.

pip install exoclaw-turn

Why

Most of exoclaw is built around the bus-driven multi-turn model: messages come in on a channel, the agent loop processes them, replies go back out. That shape is right for bots and assistants, but overkill when you just want to call an agent like a function — get one bounded run, with tool dispatch, and a return value.

run_turn is that front door. It spins up an ephemeral AgentLoop with a throwaway MessageBus and an in-memory conversation, drives a single turn to completion, and returns the result. Everything the agent loop already does — compaction on context overflow, loop detection, plugin context collection, subagent chain tracking, tool dispatch — carries over unchanged.

Usage

from exoclaw_turn import run_turn
from exoclaw_provider_litellm.provider import LiteLLMProvider
from exoclaw_openrouter_search.tool import OpenRouterSearchTool

provider = LiteLLMProvider(default_model="claude-sonnet-4-6")

result = await run_turn(
    provider=provider,
    system="You are a research assistant. Be terse.",
    message="What's the population of Reykjavik?",
    tools=[OpenRouterSearchTool()],
)

print(result.text)           # final assistant reply
print(result.tool_calls)     # tools the model invoked, in order
print(result.messages)       # all new messages produced this turn

Anything implementing the exoclaw.agent.tools.protocol.Tool protocol works as a tool — every tool plugin in the exoclaw-plugins catalog drops in unchanged.

What it inherits from AgentLoop

run_turn owns no agent behaviour of its own. It assembles the loop and reshapes the result. That means whatever lives in AgentLoop today is available through this front door:

  • Context-window compaction. Long tool chains that overflow the model's context window trigger Conversation.recover_from_overflow if implemented — for the ephemeral conversation it isn't, so the original ContextWindowExceededError surfaces. Pass a longer-lived conversation if you need recovery.
  • Loop detection. Pass iteration_policy=... (e.g. from exoclaw-loop-detection) to terminate based on tool-call patterns instead of a hard count.
  • Tool dispatch. Tools execute through the same ToolRegistry the bus-driven path uses.
  • Subagent chain tracking. If you call run_turn from inside another turn, the trace contextvars (turn.id, turn.parent_id, turn.chain) extend the parent's ancestry — same logging hierarchy as exoclaw-subagent.

Parameters

Parameter Type Default Notes
provider LLMProvider required Any provider — LiteLLM, OpenAI, etc.
message str required The user message that seeds the turn.
system str | None None System prompt. Plugin context from tools is appended.
tools list[Tool] | None None Anything implementing Tool.
model str | None provider default Override the provider's default for this turn.
max_iterations int 40 Hard cap on tool-call iterations.
temperature float 0.1 Forwarded to provider.
max_tokens int 4096 Forwarded to provider.
reasoning_effort str | None None Forwarded to provider for reasoning models.
iteration_policy IterationPolicy | None None Replace the hard count with pattern-based termination.
on_progress Callable | None None Async progress callback.

What it doesn't do

  • No persistence. State is dropped at end of turn. For multi-turn conversations, use the bus-driven AgentLoop directly, or build on top of exoclaw-conversation.
  • No streaming result. The function awaits the full turn before returning. Use on_progress for incremental feedback if you need it.
  • No multimodal attachments. The ephemeral conversation doesn't encode media into the user message content. For image/file inputs, use a bus-driven AgentLoop with a real Conversation implementation.
  • No channel. This is library-shaped. For an interactive REPL, use exoclaw-channel-cli.

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

exoclaw_turn-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

exoclaw_turn-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file exoclaw_turn-0.1.0.tar.gz.

File metadata

  • Download URL: exoclaw_turn-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for exoclaw_turn-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a75ec6bfc054fd105433155bbf11ff6ea5d346e3ec9f86db65d9a183534b1e6f
MD5 64d1c818b1458a132d36b14b5380dc29
BLAKE2b-256 71b2b0a8f6b483d9dc9d03b0b37e437df44e9c263a749aabb27584a50972f203

See more details on using hashes here.

File details

Details for the file exoclaw_turn-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: exoclaw_turn-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for exoclaw_turn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35b3f56d4df28720542b6024ff991524cf827187ec842cc6d00aecd25dcdffc3
MD5 daf9461e49fcb1d510456c8b18e5a608
BLAKE2b-256 f6a627ef5dca2a0dfa6d02c1ed84562246fb9a1a256895ba1f747ccb7645b134

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