agents
acquisition_agents
ArxivAgent
Bases: BaseAcquisitionAgent
Drop-in replacement for your existing ArxivAgent that reuses the generic flow. Keeps the same behaviors (download PDFs, image processing, summarization/RAG).
Source code in src/ursa/agents/acquisition_agents.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
BaseAcquisitionAgent
Bases: BaseAgent
A generic "acquire-then-summarize-or-RAG" agent.
Subclasses must implement
- _search(self, query) -> List[dict-like]: lightweight hits
- _materialize(self, hit) -> ItemMetadata: download or scrape and return populated item
- _id(self, hit_or_item) -> str: stable id for caching/file naming
- _citation(self, item) -> str: human-readable citation string
Optional hooks
- _postprocess_text(self, text, local_path) -> str (e.g., image interpretation)
- _filter_hit(self, hit) -> bool
Source code in src/ursa/agents/acquisition_agents.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
OSTIAgent
Bases: BaseAcquisitionAgent
Minimal OSTI.gov acquisition agent.
NOTE
- OSTI provides search endpoints that can return metadata including full-text links.
- Depending on your environment, you may prefer the public API or site scraping.
- Here we assume a JSON API that yields results with keys like: {'osti_id': '12345', 'title': '...', 'pdf_url': 'https://...pdf', 'landing_page': 'https://...'} Adapt field names if your OSTI integration differs.
Customize _search and _materialize to match your OSTI access path.
Source code in src/ursa/agents/acquisition_agents.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | |
WebSearchAgent
Bases: BaseAcquisitionAgent
Uses DuckDuckGo Search (ddgs) to find pages, downloads HTML or PDFs, extracts text, and then follows the same summarize/RAG path.
Source code in src/ursa/agents/acquisition_agents.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | |
base
Base agent class providing telemetry, configuration, and execution abstractions.
This module defines the BaseAgent abstract class, which serves as the foundation for all agent implementations in the Ursa framework. It provides:
- Standardized initialization with LLM configuration
- Telemetry and metrics collection
- Thread and checkpoint management
- Input normalization and validation
- Execution flow control with invoke/stream methods
- Graph integration utilities for LangGraph compatibility
- Runtime enforcement of the agent interface contract
Agents built on this base class benefit from consistent behavior, observability, and integration capabilities while only needing to implement the core _invoke method.
BaseAgent
Bases: ABC
Abstract base class for all agent implementations in the Ursa framework.
BaseAgent provides a standardized foundation for building LLM-powered agents with built-in telemetry, configuration management, and execution flow control. It handles common tasks like input normalization, thread management, metrics collection, and LangGraph integration.
Subclasses only need to implement the _invoke method to define their core functionality, while inheriting standardized invocation patterns, telemetry, and graph integration capabilities. The class enforces a consistent interface through runtime checks that prevent subclasses from overriding critical methods like invoke().
The agent supports both direct invocation with inputs and streaming responses, with automatic tracking of token usage, execution time, and other metrics. It also provides utilities for integrating with LangGraph through node wrapping and configuration.
Subclass Inheritance Guidelines
- Must Override: _invoke() - Define your agent's core functionality
- Can Override: _stream() - Enable streaming support _normalize_inputs() - Customize input handling Various helper methods (_default_node_tags, _as_runnable, etc.)
- Never Override: invoke() - Final method with runtime enforcement stream() - Handles telemetry and delegates to _stream call() - Delegates to invoke Other public methods (build_config, write_state, add_node)
To create a custom agent, inherit from this class and implement the _invoke method:
class MyAgent(BaseAgent):
def _invoke(self, inputs: Mapping[str, Any], **config: Any) -> Any:
# Process inputs and return results
...
Source code in src/ursa/agents/base.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | |
llm = llm
instance-attribute
Initializes the base agent with a language model and optional configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
a BaseChatModel instance. |
required | |
checkpointer
|
Optional checkpoint saver for persisting agent state. |
required | |
enable_metrics
|
Whether to collect performance and usage metrics. |
required | |
metrics_dir
|
Directory path where metrics will be saved. |
required | |
autosave_metrics
|
Whether to automatically save metrics to disk. |
required | |
thread_id
|
Unique identifier for this agent instance. Generated if not provided. |
required |
name
property
Agent name.
__call__(inputs, /, **kwargs)
Specify calling behavior for class instance.
Source code in src/ursa/agents/base.py
469 470 471 | |
__init_subclass__(**kwargs)
Ensure subclass does not override key method.
Source code in src/ursa/agents/base.py
474 475 476 477 478 479 480 481 482 | |
add_node(graph, f, node_name=None, agent_name=None)
Add a node to the state graph with token usage tracking.
This method adds a function as a node to the state graph, wrapping it to track token usage during execution. The node is identified by either the provided node_name or the function's name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
StateGraph
|
The StateGraph to add the node to. |
required |
f
|
Callable[..., Mapping[str, Any]]
|
The function to add as a node. Should return a mapping of string keys to any values. |
required |
node_name
|
Optional[str]
|
Optional name for the node. If not provided, the function's name will be used. |
None
|
agent_name
|
Optional[str]
|
Optional agent name for tracking. If not provided, the agent's name in snake_case will be used. |
None
|
Returns:
| Type | Description |
|---|---|
StateGraph
|
The updated StateGraph with the new node added. |
Source code in src/ursa/agents/base.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
ainvoke(inputs=None, /, *, raw_debug=False, save_json=None, metrics_path=None, save_raw_snapshot=None, save_raw_records=None, config=None, **kwargs)
Asynchrnously executes the agent with the provided inputs and configuration.
(Async version of invoke.)
This is the main entry point for agent execution. It handles input normalization, telemetry tracking, and proper execution context management. The method supports flexible input formats - either as a positional argument or as keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Optional[InputLike]
|
Optional positional input to the agent. If provided, all non-control keyword arguments will be rejected to avoid ambiguity. |
None
|
raw_debug
|
bool
|
If True, displays raw telemetry data for debugging purposes. |
False
|
save_json
|
Optional[bool]
|
If True, saves telemetry data as JSON. |
None
|
metrics_path
|
Optional[str]
|
Optional file path where telemetry metrics should be saved. |
None
|
save_raw_snapshot
|
Optional[bool]
|
If True, saves a raw snapshot of the telemetry data. |
None
|
save_raw_records
|
Optional[bool]
|
If True, saves raw telemetry records. |
None
|
config
|
Optional[dict]
|
Optional configuration dictionary to override default settings. |
None
|
**kwargs
|
Any
|
Additional keyword arguments that can be either: - Input parameters (when no positional input is provided) - Control parameters recognized by the agent |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The result of the agent's execution. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If both positional inputs and non-control keyword arguments are provided simultaneously. |
Source code in src/ursa/agents/base.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
build_config(**overrides)
Constructs a config dictionary for agent operations with telemetry support.
This method creates a standardized configuration dictionary that includes thread identification, telemetry callbacks, and other metadata needed for agent operations. The configuration can be customized through override parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**overrides
|
Optional configuration overrides that can include keys like 'recursion_limit', 'configurable', 'metadata', 'tags', etc. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A complete configuration dictionary with all necessary parameters. |
Source code in src/ursa/agents/base.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
invoke(inputs=None, /, *, raw_debug=False, save_json=None, metrics_path=None, save_raw_snapshot=None, save_raw_records=None, config=None, **kwargs)
Executes the agent with the provided inputs and configuration.
This is the main entry point for agent execution. It handles input normalization, telemetry tracking, and proper execution context management. The method supports flexible input formats - either as a positional argument or as keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Optional[InputLike]
|
Optional positional input to the agent. If provided, all non-control keyword arguments will be rejected to avoid ambiguity. |
None
|
raw_debug
|
bool
|
If True, displays raw telemetry data for debugging purposes. |
False
|
save_json
|
Optional[bool]
|
If True, saves telemetry data as JSON. |
None
|
metrics_path
|
Optional[str]
|
Optional file path where telemetry metrics should be saved. |
None
|
save_raw_snapshot
|
Optional[bool]
|
If True, saves a raw snapshot of the telemetry data. |
None
|
save_raw_records
|
Optional[bool]
|
If True, saves raw telemetry records. |
None
|
config
|
Optional[dict]
|
Optional configuration dictionary to override default settings. |
None
|
**kwargs
|
Any
|
Additional keyword arguments that can be either: - Input parameters (when no positional input is provided) - Control parameters recognized by the agent |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The result of the agent's execution. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If both positional inputs and non-control keyword arguments are provided simultaneously. |
Source code in src/ursa/agents/base.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
ns(runnable_or_fn, name, *extra_tags)
Return a runnable with node configuration applied.
Applies the agent's node configuration to a runnable or callable. This method should be called again after operations like .map() or subgraph .compile() as these operations may drop configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runnable_or_fn
|
A runnable or callable to configure. |
required | |
name
|
str
|
The name to assign to this node. |
required |
*extra_tags
|
str
|
Additional tags to apply to the node. |
()
|
Returns:
| Type | Description |
|---|---|
|
A configured runnable with the agent's node configuration applied. |
Source code in src/ursa/agents/base.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | |
stream(inputs, config=None, /, *, raw_debug=False, save_json=None, metrics_path=None, save_raw_snapshot=None, save_raw_records=None, **kwargs)
Streams agent responses with telemetry tracking.
This method serves as the public streaming entry point for agent interactions. It wraps the actual streaming implementation with telemetry tracking to capture metrics and debugging information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
InputLike
|
The input to process, which will be normalized internally. |
required |
config
|
Any | None
|
Optional configuration for the agent, compatible with LangGraph positional/keyword argument style. |
None
|
raw_debug
|
bool
|
If True, renders raw debug information in telemetry output. |
False
|
save_json
|
bool | None
|
If True, saves telemetry data as JSON. |
None
|
metrics_path
|
str | None
|
Optional file path where metrics should be saved. |
None
|
save_raw_snapshot
|
bool | None
|
If True, saves raw snapshot data in telemetry. |
None
|
save_raw_records
|
bool | None
|
If True, saves raw record data in telemetry. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to the streaming implementation. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[Any]
|
An iterator yielding the agent's responses. |
Note
This method tracks invocation depth to properly handle nested agent calls and ensure telemetry is only rendered once at the top level.
Source code in src/ursa/agents/base.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | |
write_state(filename, state)
Writes agent state to a JSON file.
Serializes the provided state dictionary to JSON format and writes it to the specified file. The JSON is written with non-ASCII characters preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the file where state will be written. |
required |
state
|
dict
|
Dictionary containing the agent state to be serialized. |
required |
Source code in src/ursa/agents/base.py
188 189 190 191 192 193 194 195 196 197 198 199 200 | |
code_review_agent
read_file(filename, state)
Reads in a file with a given filename into a string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
string filename to read in |
required |
Source code in src/ursa/agents/code_review_agent.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
run_cmd(query, state)
Run command from commandline
Source code in src/ursa/agents/code_review_agent.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
write_file(code, filename, state)
Writes text to a file in the given workspace as requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Text to write to a file |
required |
filename
|
str
|
the filename to write to |
required |
Returns:
| Type | Description |
|---|---|
str
|
Execution results |
Source code in src/ursa/agents/code_review_agent.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
execution_agent
Execution agent that builds a tool-enabled state graph to autonomously run tasks.
This module implements ExecutionAgent, a LangGraph-based agent that executes user instructions by invoking LLM tool calls and coordinating a controlled workflow.
Key features: - Workspace management with optional symlinking for external sources. - Safety-checked shell execution via run_command with output size budgeting. - Code authoring and edits through write_code and edit_code with rich previews. - Web search capability through DuckDuckGoSearchResults. - Summarization of the session and optional memory logging. - Configurable graph with nodes for agent, safety_check, action, and summarize.
Implementation notes: - LLM prompts are sourced from prompt_library.execution_prompts. - Outputs from subprocess are trimmed under MAX_TOOL_MSG_CHARS to fit tool messages. - The agent uses ToolNode and LangGraph StateGraph to loop until no tool calls remain. - Safety gates block unsafe shell commands and surface the rationale to the user.
Environment: - MAX_TOOL_MSG_CHARS caps combined stdout/stderr in tool responses.
Entry points: - ExecutionAgent._invoke(...) runs the compiled graph. - main() shows a minimal demo that writes and runs a script.
ExecutionAgent
Bases: BaseAgent
Orchestrates model-driven code execution, tool calls, and state management.
Orchestrates model-driven code execution, tool calls, and state management for iterative program synthesis and shell interaction.
This agent wraps an LLM with a small execution graph that alternates between issuing model queries, invoking tools (read, run, write, edit, search), performing safety checks, and summarizing progress. It manages a workspace on disk, optional symlinks, and an optional memory backend to persist summaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
BaseChatModel
|
Model identifier or bound chat model instance. If a string is provided, the BaseAgent initializer will resolve it. |
required |
agent_memory
|
Any | AgentMemory
|
Memory backend used to store summarized agent interactions. If provided, summaries are saved here. |
None
|
log_state
|
bool
|
When True, the agent writes intermediate json state to disk for debugging and auditability. |
False
|
**kwargs
|
Passed through to the BaseAgent constructor (e.g., model configuration, checkpointer). |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
safe_codes |
list[str]
|
List of trusted programming languages for the agent. Defaults to python and julia |
executor_prompt |
str
|
Prompt used when invoking the executor LLM loop. |
summarize_prompt |
str
|
Prompt used to request concise summaries for memory or final output. |
tools |
list[Tool]
|
Tools available to the agent (run_command, write_code, edit_code, read_file, run_web_search, run_osti_search, run_arxiv_search). |
tool_node |
ToolNode
|
Graph node that dispatches tool calls. |
llm |
BaseChatModel
|
LLM instance bound to the available tools. |
_action |
StateGraph
|
Compiled execution graph that implements the main loop and branching logic. |
Methods:
| Name | Description |
|---|---|
query_executor |
Send messages to the executor LLM, ensure workspace exists, and handle symlink setup before returning the model response. |
summarize |
Produce and optionally persist a summary of recent interactions to the memory backend. |
safety_check |
Validate pending run_command calls via the safety prompt and append ToolMessages for unsafe commands. |
get_safety_prompt |
Get the LLM prompt for safety_check that includes an editable list of available programming languages and gets the context of files that the agent has generated and can trust. |
_build_graph |
Construct and compile the StateGraph for the agent loop. |
_invoke |
Internal entry that invokes the compiled graph with a given recursion limit. |
action |
Disabled; direct access is not supported. Use invoke or stream entry points instead. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
Accessing the .action attribute raises to encourage using .stream(...) or .invoke(...). |
Source code in src/ursa/agents/execution_agent.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
action
property
Property used to affirm action attribute is unsupported.
__init__(llm, agent_memory=None, log_state=False, extra_tools=None, tokens_before_summarize=50000, messages_to_keep=20, safe_codes=None, **kwargs)
ExecutionAgent class initialization.
Source code in src/ursa/agents/execution_agent.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
query_executor(state)
Prepare workspace, handle optional symlinks, and invoke the executor LLM.
This method copies the incoming state, ensures a workspace directory exists (creating one with a random name when absent), optionally creates a symlink described by state["symlinkdir"], sets or injects the executor system prompt as the first message, and invokes the bound LLM. When logging is enabled, it persists the pre-invocation state to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ExecutionState
|
The current execution state. Expected keys include: - "messages": Ordered list of System/Human/AI/Tool messages. - "workspace": Optional path to the working directory. - "symlinkdir": Optional dict with "source" and "dest" keys. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ExecutionState |
ExecutionState
|
Partial state update containing: - "messages": A list with the model's response as the latest entry. - "workspace": The resolved workspace path. |
Source code in src/ursa/agents/execution_agent.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
safety_check(state)
Assess pending shell commands for safety and inject ToolMessages with results.
This method inspects the most recent AI tool calls, evaluates any run_command queries against the safety prompt, and constructs ToolMessages that either flag unsafe commands with reasons or confirm safe execution. If any command is unsafe, the generated ToolMessages are appended to the state so the agent can react without executing the command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ExecutionState
|
Current execution state. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ExecutionState |
ExecutionState
|
Either the unchanged state (all safe) or a copy with one or more ToolMessages appended when unsafe commands are detected. |
Source code in src/ursa/agents/execution_agent.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
summarize(state)
Produce a concise summary of the conversation and optionally persist memory.
This method builds a summarization prompt, invokes the LLM to obtain a compact summary of recent interactions, optionally logs salient details to the agent memory backend, and writes debug state when logging is enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ExecutionState
|
The execution state containing message history. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ExecutionState |
ExecutionState
|
A partial update with a single string message containing the summary. |
Source code in src/ursa/agents/execution_agent.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
ExecutionState
Bases: TypedDict
TypedDict representing the execution agent's mutable run state used by nodes.
Fields: - messages: list of messages (System/Human/AI/Tool) with add_messages metadata. - current_progress: short status string describing agent progress. - code_files: list of filenames created or edited in the workspace. - workspace: path to the working directory where files and commands run. - symlinkdir: optional dict describing a symlink operation (source, dest, is_linked).
Source code in src/ursa/agents/execution_agent.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
command_safe(state)
Return 'safe' if the last command was safe, otherwise 'unsafe'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ExecutionState
|
The current execution state containing messages and tool calls. |
required |
Returns: A literal "safe" if no '[UNSAFE]' tags are in the last command, otherwise "unsafe".
Source code in src/ursa/agents/execution_agent.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
should_continue(state)
Return 'summarize' if no tool calls in the last message, else 'continue'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ExecutionState
|
The current execution state containing messages. |
required |
Returns:
| Type | Description |
|---|---|
Literal['summarize', 'continue']
|
A literal "summarize" if the last message has no tool calls, |
Literal['summarize', 'continue']
|
otherwise "continue". |
Source code in src/ursa/agents/execution_agent.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
hypothesizer_agent
HypothesizerAgent
Bases: BaseAgent
Source code in src/ursa/agents/hypothesizer_agent.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
agent1_generate_solution(state)
Agent 1: Hypothesizer.
Source code in src/ursa/agents/hypothesizer_agent.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
agent2_critique(state)
Agent 2: Critic.
Source code in src/ursa/agents/hypothesizer_agent.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
agent3_competitor_perspective(state)
Agent 3: Competitor/Stakeholder Simulator.
Source code in src/ursa/agents/hypothesizer_agent.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
generate_solution(state)
Generate the overall, refined solution based on all iterations.
Source code in src/ursa/agents/hypothesizer_agent.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
summarize_process_as_latex(state)
Summarize how the solution changed over time, referencing each iteration's critique and competitor perspective, then produce a final LaTeX document.
Source code in src/ursa/agents/hypothesizer_agent.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
mp_agent
MaterialsProjectAgent
Bases: BaseAgent
Source code in src/ursa/agents/mp_agent.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
optimization_agent
run_cmd(query, state)
Run a commandline command from using the subprocess package in python
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
commandline command to be run as a string given to the subprocess.run command. |
required |
Source code in src/ursa/agents/optimization_agent.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
write_code(code, filename, state)
Writes python or Julia code to a file in the given workspace as requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The code to write |
required |
filename
|
str
|
the filename with an appropriate extension for programming language (.py for python, .jl for Julia, etc.) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Execution results |
Source code in src/ursa/agents/optimization_agent.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
planning_agent
PlanningAgent
Bases: BaseAgent
Source code in src/ursa/agents/planning_agent.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
generation_node(state)
Plan generation with structured output. Produces a JSON string in messages and a parsed list of steps in state["plan_steps"].
Source code in src/ursa/agents/planning_agent.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
PlanningState
Bases: TypedDict
State dictionary for planning agent
Source code in src/ursa/agents/planning_agent.py
40 41 42 43 44 45 46 47 48 49 | |
websearch_agent
WebSearchAgentLegacy
Bases: BaseAgent
Source code in src/ursa/agents/websearch_agent.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
process_content(url, context, state)
Processes content from a given webpage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
string with the url to obtain text content from. |
required |
context
|
str
|
string summary of the information the agent wants from the url for summarizing salient information. |
required |
Source code in src/ursa/agents/websearch_agent.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |