Session
A Session
is a conversation instance between the user and UFO. It is a continuous interaction that starts when the user initiates a request and ends when the request is completed. UFO supports multiple requests within the same session. Each request is processed sequentially, by a Round
of interaction, until the user's request is fulfilled. We show the relationship between Session
and Round
in the following figure:
Session Lifecycle
The lifecycle of a Session
is as follows:
1. Session Initialization
A Session
is initialized when the user starts a conversation with UFO. The Session
object is created, and the first Round
of interaction is initiated. At this stage, the user's request is processed by the HostAgent
to determine the appropriate application to fulfill the request. The Context
object is created to store the state of the conversation shared across all Rounds
within the Session
.
2. Session Processing
Once the Session
is initialized, the Round
of interaction begins, which completes a single user request by orchestrating the HostAgent
and AppAgent
.
3. Next Round
After the completion of the first Round
, the Session
requests the next request from the user to start the next Round
of interaction. This process continues until there are no more requests from the user.
The core logic of a Session
is shown below:
def run(self) -> None:
"""
Run the session.
"""
while not self.is_finished():
round = self.create_new_round()
if round is None:
break
round.run()
if self.application_window is not None:
self.capture_last_snapshot()
if self._should_evaluate and not self.is_error():
self.evaluation()
self.print_cost()
4. Session Termination
If the user has no more requests or decides to end the conversation, the Session
is terminated, and the conversation ends. The EvaluationAgent
evaluates the completeness of the Session
if it is configured to do so.
Reference
Bases: ABC
A basic session in UFO. A session consists of multiple rounds of interactions and conversations.
Initialize a session.
Parameters: |
|
---|
Source code in module/basic.py
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 |
|
application_window: UIAWrapper
property
writable
Get the application of the session. return: The application of the session.
context: Context
property
Get the context of the session. return: The context of the session.
cost: float
property
writable
Get the cost of the session. return: The cost of the session.
current_round: BaseRound
property
Get the current round of the session. return: The current round of the session.
evaluation_logger: logging.Logger
property
Get the logger for evaluation. return: The logger for evaluation.
id: int
property
Get the id of the session. return: The id of the session.
rounds: Dict[int, BaseRound]
property
Get the rounds of the session. return: The rounds of the session.
session_type: str
property
Get the class name of the session. return: The class name of the session.
step: int
property
Get the step of the session. return: The step of the session.
total_rounds: int
property
Get the total number of rounds in the session. return: The total number of rounds in the session.
add_round(id, round)
Add a round to the session.
Parameters: |
|
---|
Source code in module/basic.py
412 413 414 415 416 417 418 |
|
capture_last_snapshot()
Capture the last snapshot of the application, including the screenshot and the XML file if configured.
Source code in module/basic.py
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 |
|
create_following_round()
Create a following round. return: The following round.
Source code in module/basic.py
405 406 407 408 409 410 |
|
create_new_round()
abstractmethod
Create a new round.
Source code in module/basic.py
390 391 392 393 394 395 |
|
evaluation()
Evaluate the session.
Source code in module/basic.py
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 |
|
experience_saver()
Save the current trajectory as agent experience.
Source code in module/basic.py
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 |
|
initialize_logger(log_path, log_filename, mode='a', configs=configs)
staticmethod
Initialize logging. log_path: The path of the log file. log_filename: The name of the log file. return: The logger.
Source code in module/basic.py
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 |
|
is_error()
Check if the session is in error state. return: True if the session is in error state, otherwise False.
Source code in module/basic.py
582 583 584 585 586 587 588 589 |
|
is_finished()
Check if the session is ended. return: True if the session is ended, otherwise False.
Source code in module/basic.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
|
next_request()
abstractmethod
Get the next request of the session. return: The request of the session.
Source code in module/basic.py
397 398 399 400 401 402 403 |
|
print_cost()
Print the total cost of the session.
Source code in module/basic.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
|
request_to_evaluate()
abstractmethod
Get the request to evaluate. return: The request(s) to evaluate.
Source code in module/basic.py
608 609 610 611 612 613 614 |
|
run()
Run the session.
Source code in module/basic.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|