Skip to main content

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 depends on autourgos-agent (for the shared CallbackHandler interface).


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

my_llm is any chat-model instance, e.g. OpenAIChatModel from autourgos-openaichat (needs OPENAI_API_KEY set). my_tool is any plain callable used as an agent tool.

from autourgos_hcix import HcixInterruptMiddleware
from autourgos_agent import Agent
from autourgos_openaichat import OpenAIChatModel

my_llm = OpenAIChatModel(model="gpt-4o-mini")

def my_tool(query: str) -> str:
    return f"Result for: {query}"

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

agent = Agent(
    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.

Because verbose=True is set above, HCIx also narrates the injection into the agent's verbose trace, for example:

[HCIx] Human override injected: 'Stop researching and summarize what you have so far.'

Async Usage

import asyncio

from autourgos_hcix import HcixInterruptMiddleware
from autourgos_agent import Agent

agent = Agent(
    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-agent, this injects the override for the following reasoning step.
on_agent_end / on_agent_error Stops hotkey listeners and logs total paused time.

agent.scratchpad is a real, live instance attribute on autourgos-agent, so HCIx injects the override directly into it (in addition to agent.system_prompt) and the running agent picks it up on its very next LLM call.


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

Metadata

Release files for autourgos-hcix 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autourgos-hcix 3.1.0
File Size Uploaded
autourgos_hcix-3.1.0.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autourgos-hcix 3.1.0
File Interpreter ABI Platform
autourgos_hcix-3.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.1 kB

Release files / autourgos_hcix-3.1.0.tar.gz

Download URL autourgos_hcix-3.1.0.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
812edb514c2ce79af1b074fb2b3ade649a22cf211e084014d53edb9b1722dd4d
BLAKE2b-256 checksum
How to use checksums
2d6dfcbe91fac94c2595b9b9ec00c9ad7fdb513d40d6212299b6d5d2d3c45897
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / autourgos_hcix-3.1.0-py3-none-any.whl

Download URL autourgos_hcix-3.1.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5eec549f095a531fe7f2443fbc7e04a672061e4a33ce11b176892ab8970058a
BLAKE2b-256 checksum
How to use checksums
2309b94236f8bab0653c6c5e27505363efcf9083049fe53abe30a1c8db82b3fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

3.3.0

2 release files

3.2.6

2 release files

3.2.3

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.1.2

2 release files

3.1.1

2 release files

This release

3.1.0 This release

2 release files

3.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page