TextualAgent
See also
- This agent subclass builds on top of the default agent, make sure to read that first.
- This class powers the
mini
command line tool, see usage for more details.
minisweagent.agents.interactive_textual.TextualAgent
TextualAgent(model, env, **kwargs)
Bases: App
Source code in src/minisweagent/agents/interactive_textual.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
BINDINGS
class-attribute
instance-attribute
BINDINGS = [
Binding(
"right,l",
"next_step",
"Step++",
tooltip="Show next step of the agent",
),
Binding(
"left,h",
"previous_step",
"Step--",
tooltip="Show previous step of the agent",
),
Binding(
"0",
"first_step",
"Step=0",
tooltip="Show first step of the agent",
show=False,
),
Binding(
"$",
"last_step",
"Step=-1",
tooltip="Show last step of the agent",
show=False,
),
Binding(
"j,down", "scroll_down", "Scroll down", show=False
),
Binding("k,up", "scroll_up", "Scroll up", show=False),
Binding(
"q,ctrl+q", "quit", "Quit", tooltip="Quit the agent"
),
Binding(
"y,ctrl+y",
"yolo",
"YOLO mode",
tooltip="Switch to YOLO Mode (LM actions will execute immediately)",
),
Binding(
"c",
"confirm",
"CONFIRM mode",
tooltip="Switch to Confirm Mode (LM proposes commands and you confirm/reject them)",
),
Binding(
"u,ctrl+u",
"human",
"HUMAN mode",
tooltip="Switch to Human Mode (you can now type commands directly)",
),
Binding(
"f1,question_mark",
"toggle_help_panel",
"Help",
tooltip="Show help",
),
]
agent_state
instance-attribute
agent_state = 'UNINITIALIZED'
agent
instance-attribute
agent = _TextualAgent(self, model=model, env=env, **kwargs)
n_steps
instance-attribute
n_steps = 1
log_handler
instance-attribute
log_handler = AddLogEmitCallback(
lambda record: call_from_thread(
on_log_message_emitted, record
)
)
exit_status
instance-attribute
exit_status: str = 'ExitStatusUnset'
result
instance-attribute
result: str = ''
config
property
config
i_step
property
writable
i_step: int
Current step index.
messages
property
messages: list[dict]
model
property
model
env
property
env
run
run(task: str, **kwargs) -> tuple[str, str]
Source code in src/minisweagent/agents/interactive_textual.py
279 280 281 282 |
|
compose
compose() -> ComposeResult
Source code in src/minisweagent/agents/interactive_textual.py
303 304 305 306 307 308 309 310 |
|
on_mount
on_mount() -> None
Source code in src/minisweagent/agents/interactive_textual.py
312 313 314 315 |
|
on_message_added
on_message_added() -> None
Source code in src/minisweagent/agents/interactive_textual.py
331 332 333 334 335 336 |
|
on_log_message_emitted
on_log_message_emitted(record: LogRecord) -> None
Handle log messages of warning level or higher by showing them as notifications.
Source code in src/minisweagent/agents/interactive_textual.py
338 339 340 341 |
|
on_unmount
on_unmount() -> None
Clean up the log handler when the app shuts down.
Source code in src/minisweagent/agents/interactive_textual.py
343 344 345 346 |
|
on_agent_finished
on_agent_finished(exit_status: str, result: str)
Source code in src/minisweagent/agents/interactive_textual.py
348 349 350 351 352 353 |
|
update_content
update_content() -> None
Source code in src/minisweagent/agents/interactive_textual.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
get_system_commands
get_system_commands(
screen: Screen,
) -> Iterable[SystemCommand]
Source code in src/minisweagent/agents/interactive_textual.py
400 401 402 403 404 405 |
|
action_yolo
action_yolo()
Source code in src/minisweagent/agents/interactive_textual.py
409 410 411 412 413 |
|
action_human
action_human()
Source code in src/minisweagent/agents/interactive_textual.py
415 416 417 418 419 |
|
action_confirm
action_confirm()
Source code in src/minisweagent/agents/interactive_textual.py
421 422 423 424 425 |
|
action_next_step
action_next_step() -> None
Source code in src/minisweagent/agents/interactive_textual.py
427 428 |
|
action_previous_step
action_previous_step() -> None
Source code in src/minisweagent/agents/interactive_textual.py
430 431 |
|
action_first_step
action_first_step() -> None
Source code in src/minisweagent/agents/interactive_textual.py
433 434 |
|
action_last_step
action_last_step() -> None
Source code in src/minisweagent/agents/interactive_textual.py
436 437 |
|
action_scroll_down
action_scroll_down() -> None
Source code in src/minisweagent/agents/interactive_textual.py
439 440 |
|
action_scroll_up
action_scroll_up() -> None
Source code in src/minisweagent/agents/interactive_textual.py
442 443 |
|
action_toggle_help_panel
action_toggle_help_panel() -> None
Source code in src/minisweagent/agents/interactive_textual.py
445 446 447 448 449 |
|
minisweagent.agents.interactive_textual.TextualAgentConfig
dataclass
TextualAgentConfig(
system_template: str = "You are a helpful assistant that can do anything.",
instance_template: str = "Your task: {{task}}. Please reply with a single shell command in triple backticks. To finish, the first line of the output of the shell command must be 'COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT'.",
timeout_template: str = "The last command <command>{{action['action']}}</command> timed out and has been killed.\nThe output of the command was:\n <output>\n{{output}}\n</output>\nPlease try another command and make sure to avoid those requiring interactive input.",
format_error_template: str = "Please always provide EXACTLY ONE action in triple backticks.",
action_observation_template: str = "Observation: {{output}}",
step_limit: int = 0,
cost_limit: float = 3.0,
mode: Literal["confirm", "yolo"] = "confirm",
whitelist_actions: list[str] = list(),
confirm_exit: bool = True,
)
Bases: AgentConfig
mode
class-attribute
instance-attribute
mode: Literal['confirm', 'yolo'] = 'confirm'
Mode for action execution: 'confirm' requires user confirmation, 'yolo' executes immediately.
whitelist_actions
class-attribute
instance-attribute
whitelist_actions: list[str] = field(default_factory=list)
Never confirm actions that match these regular expressions.
confirm_exit
class-attribute
instance-attribute
confirm_exit: bool = True
If the agent wants to finish, do we ask for confirmation from user?
minisweagent.agents.interactive_textual.SmartInputContainer
SmartInputContainer(app: TextualAgent)
Bases: Container
Smart input container supporting single-line and multi-line input modes.
Source code in src/minisweagent/agents/interactive_textual.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
can_focus
instance-attribute
can_focus = True
display
instance-attribute
display = False
pending_prompt
instance-attribute
pending_prompt: str | None = None
compose
compose() -> ComposeResult
Source code in src/minisweagent/agents/interactive_textual.py
150 151 |
|
on_mount
on_mount() -> None
Initialize the widget state.
Source code in src/minisweagent/agents/interactive_textual.py
153 154 155 156 |
|
on_focus
on_focus() -> None
Called when the container gains focus.
Source code in src/minisweagent/agents/interactive_textual.py
158 159 160 161 162 163 |
|
request_input
request_input(prompt: str) -> str
Request input from user. Returns input text (empty string if confirmed without reason).
Source code in src/minisweagent/agents/interactive_textual.py
165 166 167 168 169 170 171 172 173 174 |
|
action_toggle_mode
action_toggle_mode() -> None
Switch from single-line to multi-line mode (one-way only).
Source code in src/minisweagent/agents/interactive_textual.py
192 193 194 195 196 197 198 199 |
|
on_input_submitted
on_input_submitted(event: Submitted) -> None
Handle single-line input submission.
Source code in src/minisweagent/agents/interactive_textual.py
217 218 219 220 221 |
|
on_key
on_key(event: Key) -> None
Handle key events.
Source code in src/minisweagent/agents/interactive_textual.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
minisweagent.agents.interactive_textual.AddLogEmitCallback
AddLogEmitCallback(callback)
Bases: Handler
Custom log handler that forwards messages via callback.
Source code in src/minisweagent/agents/interactive_textual.py
102 103 104 105 |
|
callback
instance-attribute
callback = callback
emit
emit(record: LogRecord)
Source code in src/minisweagent/agents/interactive_textual.py
107 108 |
|