How AgentAPI processes terminal output
mainAgentAPI uses an in-memory terminal emulator to translate API calls into keystrokes and parse terminal output into discrete messages.
Message Splitting Logic
- Initial State: The terminal output present before any user messages are sent is treated as the agent's first message.
- User Input: When a user sends a message via the API, a terminal snapshot is taken before keystrokes are sent.
- Agent Response: After the user message is submitted, AgentAPI takes snapshots whenever the terminal output changes. It diffs these against the previous snapshot; any new text appearing below the previous content is treated as a new agent message.
- Updates: If the terminal changes again before the next user message, the current agent message is updated.
TUI Element Removal
To provide a clean chat experience, AgentAPI automatically strips:
- User Echo: Lines containing the text of the user's last message.
- Input Boxes: Lines at the end of a message containing common TUI elements like
>or------.