Skip to main content

Human Cognitive Interrupt middleware for Autourgos agents with global hotkey steering.

Project description

autourgos-hcix

Human Cognitive Interrupt (HCIx) middleware for Autourgos agents.

Press a global shortcut during a long-running agent task, type a high-priority instruction, and the middleware injects that instruction into the agent so the next reasoning step is steered by the human operator.


Why use this?

Long-running agents sometimes need live human steering:

  • Stop drift - redirect an agent when its current plan is no longer useful
  • Inject new context - add fresh information without restarting the run
  • Pause for operator input - wait while a person writes a corrective instruction
  • Keep cleanup reliable - unregister hotkey listeners when the run ends or errors

HcixInterruptMiddleware is self-contained and has zero required runtime dependencies.


Install

pip install autourgos-hcix

For global hotkey support on Linux/macOS, install the optional pynput extra:

pip install 'autourgos-hcix[hcix]'

Windows uses the native RegisterHotKey API. Tkinter is used for the desktop prompt when available; otherwise HCIx falls back to a console prompt.


Quick Start

from autourgos_hcix import HcixInterruptMiddleware
from autourgos_react_agent import ReactAgent

middleware = HcixInterruptMiddleware(shortcut="ctrl+shift+h")

agent = ReactAgent(
    llm=my_llm,
    tools=[my_tool],
    middleware=[middleware],
    verbose=True,
)

result = agent.invoke("Research this task and keep working until you have a final answer.")
print(result)

During the run, press ctrl+shift+h, type the new instruction, then send it. HCIx injects an authoritative override block into the agent context.


Async Usage

import asyncio

from autourgos_hcix import HcixInterruptMiddleware
from autourgos_react_agent import ReactAgent

agent = ReactAgent(
    llm=my_llm,
    tools=[my_tool],
    middleware=[HcixInterruptMiddleware(shortcut="ctrl+alt+k")],
)

async def main() -> None:
    result = await agent.ainvoke("Prepare a detailed cloud service comparison.")
    print(result)

asyncio.run(main())

HCIx uses the same lifecycle hooks in sync and async agent runs. When the user is actively writing an interrupt, the hook waits until the instruction is submitted or cancelled.


Programmatic Interrupts

You can submit an interrupt without using a keyboard shortcut. This is useful for tests, APIs, dashboards, and notebooks.

from autourgos_hcix import CognitiveInterruptManager, HcixInterruptMiddleware

manager = CognitiveInterruptManager(enable_hotkey=False)
middleware = HcixInterruptMiddleware(manager=manager)

manager.submit_instruction("Stop searching. Summarize only the sources already collected.")

At the next supported middleware hook, the instruction is consumed and injected once.


Human Approval Primitives

The package also includes programmatic approval helpers.

from autourgos_hcix import HumanInterrupt, HumanInterruptHandler, HumanStateEditor

state = {"step": "delete_files", "count": 3}
edited = HumanStateEditor.edit(state, {"count": 2})

handler = HumanInterruptHandler()

# Worker thread:
# action, edits = handler.wait_for_human(timeout=60.0)

# UI/API thread later:
# handler.submit("approve", edited)

Agent Hooks

HCIx uses standard Autourgos middleware hooks:

Hook Behavior
on_iteration_start(iteration, agent=...) Polls before the next LLM call when the host agent exposes this hook.
on_iteration(iteration, thought, ...) Polls after an iteration event. In autourgos-react-agent, this injects the override for the following reasoning step.
on_agent_end / on_agent_error Stops hotkey listeners and logs total paused time.

The current ReactAgent keeps its scratchpad local to the loop, so HCIx injects into agent.system_prompt when no public scratchpad is available.


Constructor Parameters

Parameter Type Default Description
shortcut str "ctrl+shift+h" Global hotkey, such as "ctrl+shift+h" or "ctrl+alt+k".
manager CognitiveInterruptManager None Optional preconfigured manager for tests or custom UIs.
poll_interval float 0.25 Seconds between checks while the human prompt is open.
inject_into_system_prompt bool True Add override text to agent.system_prompt when available.
inject_into_scratchpad bool True Add override text to agent.scratchpad when the agent exposes one.
enable_hotkey bool True Start the global hotkey listener. Disable for tests, servers, and headless runs.

Package Structure

autourgos-hcix/
|-- autourgos_hcix/
|   |-- __init__.py
|   |-- base.py
|   |-- hcix.py
|   |-- interrupt.py
|   |-- middleware.py
|   `-- py.typed
|-- tests/
|   `-- test_hcix_interrupt.py
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
`-- pyproject.toml

Requirements

  • Python 3.9+
  • Optional: pynput for non-Windows global hotkeys
  • Optional: Tkinter for the desktop prompt UI

Links


License

MIT - see LICENSE

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

autourgos_hcix-1.0.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

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

autourgos_hcix-1.0.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file autourgos_hcix-1.0.0.tar.gz.

File metadata

  • Download URL: autourgos_hcix-1.0.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for autourgos_hcix-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5a67949cfb5336bd21465288c7800987e92ef03091302ea3ec1270a7aaad6025
MD5 f3a864bdfe14fa1d7e91cad3b5b1b0bf
BLAKE2b-256 7b064c6844c7d222dd3beb1b71a24a14cf4ed3bf0882518b3352c6306a848f5d

See more details on using hashes here.

File details

Details for the file autourgos_hcix-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: autourgos_hcix-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for autourgos_hcix-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e068727eea7bb3aa4c197458cb67f821bdf80b38dca93eb5f5730eee6351d6dd
MD5 255c636cd760f1af978acbd94d2740a1
BLAKE2b-256 f89fe65561f35bb6dbf6b9d98d2082d40fccb95e912d37f3899012eaed9b799a

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