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 it so the next reasoning step is steered by the human operator.
from autourgos_hcix import HcixInterruptMiddleware
from autourgos_agent import Agent
from autourgos_openaichat import OpenAIChatModel
middleware = HcixInterruptMiddleware(shortcut="ctrl+shift+h")
agent = Agent(llm=OpenAIChatModel(model="gpt-4o-mini"), middleware=[middleware], verbose=True)
result = agent.invoke("Research this task and keep working until you have a final answer.")
Features
- Global-hotkey live steering — interrupt a running agent, type a correction, and the next reasoning step picks it up
- Programmatic interrupts — submit an instruction without a keyboard, for tests, APIs, dashboards, notebooks
- Human approval primitives —
HumanInterrupt,HumanInterruptHandler,HumanStateEditorfor worker-thread-blocks-until-a-human-decides workflows - Native on Windows (
RegisterHotKey),pynputoptional extra for Linux/macOS - Cleanup guaranteed — hotkey listeners unregister on run end or error
- Safe to share across agents — one
HcixInterruptMiddlewareinstance can serve multiple concurrentAgents; per-agent injected-override state is isolated (autourgos-core'sPerAgentRegistry)
Table of Contents
- Why Use This?
- Install
- Quick Start
- Async Usage
- Programmatic Interrupts
- Human Approval Primitives
- Agent Hooks
- Constructor Parameters
- License
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. With verbose=True, HCIx also narrates the injection into the
agent's verbose trace:
[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
Submit an interrupt without using a keyboard shortcut — 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.
Autonomous / Headless Agents
Global hotkeys and desktop prompts assume a human is sitting at a keyboard. An autonomous
agent running on a server, in a container, or in the cloud has neither — there's no DISPLAY
for pynput to bind to, and no one to press ctrl+shift+h.
For these deployments, skip the hotkey listener entirely and drive HCIx from your own control plane (an API endpoint, a queue consumer, a supervisor process) instead:
from autourgos_hcix import CognitiveInterruptManager, HcixInterruptMiddleware
manager = CognitiveInterruptManager.headless()
middleware = HcixInterruptMiddleware(manager=manager)
# elsewhere -- an API handler, a queue consumer, an operator dashboard:
manager.submit_instruction("Stop researching. Summarize what you have.")
CognitiveInterruptManager.headless() is shorthand for enable_hotkey=False. On a headless
box, enable_hotkey=True (the default) also degrades safely on its own -- no DISPLAY/
WAYLAND_DISPLAY means HCIx skips the hotkey listener without attempting to import pynput --
but for an autonomous deployment, being explicit is clearer than relying on that fallback.
Human Approval Primitives
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. |
Requirements
- Python 3.9+
- Optional:
pynputfor non-Windows global hotkeys - Optional: Tkinter for the desktop prompt UI
License
Apache License 2.0, Copyright (c) 2026 Jitin Kumar Sengar
Metadata
Release files for autourgos-hcix 3.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autourgos_hcix-3.2.6.tar.gz | 31.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autourgos_hcix-3.2.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 56.4 kB
Release files / autourgos_hcix-3.2.6.tar.gz
| Download URL | autourgos_hcix-3.2.6.tar.gz |
|---|---|
| Size | 31.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0aee70c43237d8600d45bfb4156c6488c0b92454bc4769389b16b6ca3e350515
|
|
BLAKE2b-256 checksum How to use checksums |
4ed18e9f5dbecc7620cf3076cff6dc22eb7c71462aa4f8a02885090c38aaaa8d
|
| 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.2.6-py3-none-any.whl
| Download URL | autourgos_hcix-3.2.6-py3-none-any.whl |
|---|---|
| Size | 24.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72fb1d2b07f3c57fec51d644fd947cdd43f5025d0e052230893bc2726edd4fc8
|
|
BLAKE2b-256 checksum How to use checksums |
7f8f99cce1bbff668c2fd3c4ebd83f8ac7dd6dd522699408fe67504a3ba0939b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|