Skip to content

feat: add --prompt flag for headless single-shot execution#79

Open
velocitybolt wants to merge 2 commits intomindsdb:mainfrom
velocitybolt:feat/headless-prompt
Open

feat: add --prompt flag for headless single-shot execution#79
velocitybolt wants to merge 2 commits intomindsdb:mainfrom
velocitybolt:feat/headless-prompt

Conversation

@velocitybolt
Copy link
Copy Markdown

Enable programmatic usage of Anton via CLI flags:
--prompt/-p Run a single query and exit
--output-format Return text (default) or structured JSON
--stdin Read prompt from stdin for piping

Headless mode reuses the full ChatSession pipeline (memory, tools,
scratchpad, datasources) without any interactive elements — no
prompt_toolkit, no spinner, no escape watcher.

JSON output includes response text, tool calls, and token usage
for easy integration with orchestration platforms and CI pipelines.

Running Example:
image

  Enable programmatic usage of Anton via CLI flags:
    --prompt/-p    Run a single query and exit
    --output-format  Return text (default) or structured JSON
    --stdin        Read prompt from stdin for piping

  Headless mode reuses the full ChatSession pipeline (memory, tools,
  scratchpad, datasources) without any interactive elements — no
  prompt_toolkit, no spinner, no escape watcher.

  JSON output includes response text, tool calls, and token usage
  for easy integration with orchestration platforms and CI pipelines.
@torrmal
Copy link
Copy Markdown
Contributor

torrmal commented Apr 7, 2026

thank you @velocitybolt , this is a great innitiative, @ZoranPandovski can you please review.

Copy link
Copy Markdown
Member

@ZoranPandovski ZoranPandovski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @velocitybolt. Please check my comments

anton/chat.py Outdated
tool_calls: list[dict] = []
usage_data: dict = {}

async for event in session.turn_stream(prompt):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add try/except and make sure we print the error to stderr

anton/chat.py Outdated
asyncio.run(_chat_loop(console, settings, resume=resume, first_run=first_run, desktop_first_run=desktop_first_run))


def run_headless(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we are trying to decouple the chat.py scirpt so it would be better if you can migrate this under a new file in commands/dir

resume: bool = typer.Option(
False, "--resume", "-r", help="Resume a previous chat session"
),
prompt: str | None = typer.Option(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if a user pass propmpt and stdin simultaneously? Maybe we catch this and return and error that theyt are mutually exclusive

prompt: str | None = typer.Option(
None, "--prompt", "-p", help="Run a single prompt in headless mode and exit"
),
output_format: str = typer.Option(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we add a guard in case this is used outsidde headless mode

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@velocitybolt
Copy link
Copy Markdown
Author

Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.

I have read the CLA Document and I hereby sign the CLA

You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

I have read the CLA Document and I hereby sign the CLA

@velocitybolt
Copy link
Copy Markdown
Author

recheck

@velocitybolt
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Apr 8, 2026
@torrmal
Copy link
Copy Markdown
Contributor

torrmal commented Apr 10, 2026

@ZoranPandovski anything else we need here, should this merge go into v2 instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants