agents¶
athena.agents
¶
run_investing_agent(portfolio_file_name, project_code, events_section_title, events_description, data_source_description, data_summary_description, generate_summary=False, system_prompt_file='system_prompt.j2', pricing_manager=None, use_commodities=False, short_ok=False)
¶
Run the investing agent with the given configuration.
Loads the portfolio, builds a system prompt, generates an initial message, and enters a conversation loop with the LLM that can execute QUOTE, BUY, and SELL commands. Saves the portfolio after the loop completes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
portfolio_file_name
|
str
|
Path to the portfolio Excel file. |
required |
project_code
|
str
|
The project code for fetching events. |
required |
events_section_title
|
str
|
Title for the events section. |
required |
events_description
|
str
|
Description of the events data. |
required |
data_source_description
|
str
|
Description of the data source. |
required |
data_summary_description
|
str
|
Description for the data summary. |
required |
generate_summary
|
bool
|
Whether to generate an email summary at the end. |
False
|
system_prompt_file
|
str
|
Jinja2 template filename for the system prompt. |
'system_prompt.j2'
|
pricing_manager
|
Optional pricing manager passed to portfolio loading. |
None
|
|
use_commodities
|
bool
|
If True, use commodity futures quote functions instead of stock quote functions. |
False
|
short_ok
|
bool
|
If True, allow short selling and use corresponding prompt templates. |
False
|
Returns:
| Type | Description |
|---|---|
|
The email summary string if |
|
|
otherwise an empty string. |
Source code in src/athena/agents/agents.py
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 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 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | |
get_quote(symbol)
¶
Get the latest ask/bid quote for a stock symbol via the Massive API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock ticker symbol (e.g., "AAPL"). |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
A tuple of (ask_price, bid_price). Returns (-1.0, -1.0) on error. |
Source code in src/athena/agents/agents.py
get_quote_for_context(symbol)
¶
Get comprehensive quote information for a stock symbol for LLM context.
Includes bid/ask, current day OHLC (if market open), and price movements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock ticker symbol (e.g., "AAPL"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
A newline-joined string with stock info, bid/ask prices, market |
str
|
status, OHLC data, and 1-week/1-month/1-year price changes. |
Source code in src/athena/agents/agents.py
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 | |
stream_llm_response(system_prompt, messages, model)
¶
Send messages to an Anthropic LLM and return the response text.
Retries up to 3 times with exponential backoff on failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system_prompt
|
str
|
The system prompt to prepend to the conversation. |
required |
messages
|
list[dict[str, str]]
|
List of message dicts with "role" and "content" keys. |
required |
model
|
str
|
Anthropic model name (e.g., "claude-sonnet-4-5"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text content of the model's response. |
Raises:
| Type | Description |
|---|---|
Exception
|
Re-raises the last exception after all retry attempts are exhausted. |
Source code in src/athena/agents/agents.py
generate_initial_message(portfolio, project_code, events_section_title, events_description, use_commodities=False, short_ok=False)
¶
Generate the initial user message from a Jinja2 template.
Fetches events data, calculates portfolio values, and optionally includes available commodity contracts to compose the first message sent to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
portfolio
|
Portfolio
|
The portfolio to summarize in the message. |
required |
project_code
|
str
|
The Emerging Trajectories project code for events. |
required |
events_section_title
|
str
|
Title for the events section in the message. |
required |
events_description
|
str
|
Description of the events data source. |
required |
use_commodities
|
bool
|
If True, include available futures contract info. |
False
|
short_ok
|
bool
|
If True, use the short-selling-enabled message template. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered initial message string ready to send to the LLM. |
Source code in src/athena/agents/agents.py
get_system_prompt(data_source_description, data_summary_description, system_prompt_file='system_prompt.j2')
¶
Generate system prompt from a Jinja2 template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_source_description
|
str
|
Description of the data source to inject into the prompt. |
required |
data_summary_description
|
str
|
Description of the data summary to inject into the prompt. |
required |
system_prompt_file
|
str
|
Jinja2 template filename for the system prompt. |
'system_prompt.j2'
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered system prompt string. |
Source code in src/athena/agents/agents.py
get_email_summary_instructions()
¶
Load email summary instructions from a Jinja2 template.
Returns:
| Type | Description |
|---|---|
str
|
The rendered email summary instructions string. |