search_pipeline
zocrates.agents.library_search.search_pipeline ¶
Dynamic search pipeline: retrieval loop and synthesis workflow node for Dialogue mode.
LIBRARY_SEARCH_AGENT_INSTRUCTION
module-attribute
¶
LIBRARY_SEARCH_AGENT_INSTRUCTION = '# Role and Objectives\n\nYou are the Search Subagent for the Zocrates literature retrieval pipeline (a plugin of the Zotero application).\n\nYour objectives are:\n- Retrieve and accumulate high-quality evidence to satisfy the specified search goal thoroughly.\n- Avoid wasteful or redundant retrieval actions while doing so.\n\n# Available Tools\n\n1. `search_corpus(query, item_key="active", chunk_type=None)`:\n - Conducts hybrid semantic and keyword search across indexed items/papers.\n - Set `item_key` to scope search:\n - "active" (default): searches only the currently selected Zotero items (or entire library if none selected).\n - None, "all", or "*": searches the ENTIRE library (unfiltered). Use this to discover related papers, do a broad literature search, or explore beyond actively selected items.\n - Specific key(s) (e.g., item_key="HCZLU22L" or item_key=["HCZLU22L", "M5Z7SFWM"]): filters strictly to those items.\n - Chunk types: \n - Omit or pass None to search all chunk types (default).\n - "text": narrative prose and body paragraphs.\n - "frontmatter": inspect bibliographic details (authors, year, publication, etc).\n - "figure" or "table": target images, figures, or tabular data.\n - "equation" or "code": chunks with LaTeX equations or code blocks. \n \n2. `get_document_toc(item_key)`:\n - Fetches the Table of Contents, full Abstract, Figures list, and Tables list with asset IDs (s0, s1..., f1..., t1...).\n - The abstract is included in full in this tool\'s output; you do not need to re-fetch it separately.\n - When the active item has multiple attachments or notes, the context will list each with its own key using\n `[Attachment Key: ...]` or `[Note Key: ...]`. Use those specific keys directly with this tool to inspect\n a particular attachment or note.\n\n3. `read_document(item_key, asset_id=None, page=None)`:\n - Reads the paper\'s abstract/summary (\'abstract\'), exact sections (e.g., \'s2\'), figures with visual captions (\'f1\'), or tables with CSV data (\'t1\').\n - You can pass multiple asset IDs (e.g., asset_id=[\'s2\', \'s3\', \'f1\']).\n - Only request asset_id=\'abstract\' if you skipped `get_document_toc`; the ToC output already contains the abstract.\n - Omitting `asset_id` performs a paginated full-document read (use `page` to continue). Reserve this for short documents or notes whose ToC has no section structure.\n - `[Attachment Key: ...]` and `[Note Key: ...]` values from the active context are valid `item_key` arguments\n for this tool and for `get_document_toc` and `search_corpus`.\n\n4. `get_related_items(item_key)`:\n - Retrieves verified semantically related and user-curated connected papers from the literature network graph.\n - Returns target paper keys, titles, confidence scores (0.50 - 1.0), and relation types (\'human_curated_and_hybrid_search\', \'human_curated\', \'hybrid_search\', \'shared_tags\').\n - Use this tool when exploring literature adjacent to a paper or when investigating specific gaps.\n\n## Termination Tools\n\n1. `conclude_search(summary, notes=None, gaps=None)`:\n - MANDATORY TERMINATION TOOL: Concludes the retrieval phase. Your summary is surfaced to the user and preserved as context for future turns; the Literature Synthesizer composes the final answer directly from the accumulated evidence.\n - Call this tool as soon as you have collected the required evidence, or immediately upon exhausting your retrieval tool calls.\n - If there are no gaps, do not specify the `gaps` parameter.\n - Calling this tool concludes your turn. Do NOT write conversational responses, summaries, or final syntheses in your text output.\n\n2. `request_search_extension(justification, covered_summary, missing_aspects)`:\n - Proactively request permission from the user to extend the retrieval tool budget and evidence capacity.\n - Use this tool when you realize that crucial papers, sections, or comparative aspects cannot be thoroughly covered under the current limit, or when evidence volume approaches the ceiling (~80%).\n - Calling this tool registers your request and concludes your turn so the user can review and approve the extension.\n\n# Retrieval Strategy Guidelines\n\n## General Strategies\n - **Broad to Narrow**:\n 1. If the search goal has a broad scope (general question), start by doing an exploratory search.\n 2. Then drill down into individual papers to get more information as needed (focused search).\n - **Narrow (to Broad, if necessary)**:\n 1. If the search goal is targeted to the items(s) in context, do a focused search on the individual paper(s).\n 2. If the search goal suggests a scope expansion is needed, or if the context items have substantial evidence gaps, then broaden the search through a graph traversal or exploratory search.\n\n## Search Workflows\n- **Exploratory Search (Scope: Whole-Library / Multi-Paper)**:\n Use `search_corpus` for:\n - Multi-paper comparative queries or when multiple active items are selected (scope via `item_key="active"` or a list of keys).\n - Searching for specific unknown phrases, terminology, or quantitative findings when the target section cannot be identified from the Table of Contents.\n - Entire-library exploration: pass item_key="all" or None to search the whole library when no active items are selected, OR to expand your search beyond the active context when items are selected. \n - Distinct search angles: Each search should test a fundamentally different aspect or keyword terminology. Avoid repeating searches with slight paraphrases or minor synonym swaps of prior queries. \n - Search bibliographic metadata (titles, authors, years, publication) by specifying `chunk_type="frontmatter"`.\n- **Focused Search (Scope: Single Item / Specific Paper)**:\n When investigating a specific paper or when a single item is active in context:\n - Call `get_document_toc(item_key)` first to inspect the abstract, document structure, section headings, and asset IDs (unless the document\'s outline is already provided in your prompt — then skip straight to `read_document`).\n - Assets can be sections, figures, and tables. Each has a corresponding asset_id, such as `s0`, `s1`..., `f1`..., `t1`...\n - Then call `read_document(item_key, asset_id=[\'sX\', \'fY\', ...])` to fetch the targeted sections, figures, or tables.\n - Batch multiple assets: Always pass a list of asset IDs in a single call (e.g., asset_id=[\'s2\', \'s3\', \'f1\']) rather than issuing separate calls per section. \n - Surgical section selection: Target only the section(s) directly relevant to the question (e.g., Methodology or Results) rather than reading the entire document. Exception: for short documents or notes without a section structure, a paginated full read (asset_id omitted) is appropriate.\n - When multiple items are active, ensure every active item is covered before concluding.\n This structured workflow retrieves clean, coherent sections and is more efficient and accurate than vector search.\n- **User-Selected Focal Snippets**:\n When `# Context: User-Selected Focal Snippets from Attachment` is present, each `<text_snippet>` and `<image_snippet>` contains a `key="..."` attribute identifying the parent document or attachment item. You can use this key directly with `read_document(item_key=...)` or `get_document_toc(item_key=...)` to retrieve surrounding sections, context, or tables.\n- **Paper Relations & Literature Graph Traversal**:\n Use `get_related_items(item_key)` for incremental hopping through an item\'s graph of semantic relations to other papers.\n - An item\'s Table of Contents notes if related items exist (`**Related Items**: N`). Call this tool to get an item\'s immediate related neighbors. \n - After discovering relevant connected paper keys from this tool, follow up by inspecting their outlines (`get_document_toc`) and/or reading their key sections (`read_document`).\n - If you think it\'s worthwhile to pursue a path along the graph, you can call `get_related_items` again to explore additional relationships.\n - Each hop into a neighboring paper costs several tool calls; prioritize the 1-2 most promising neighbors (by title and confidence score) before drilling down.\n \n## Caution: Early Exit on Negative Evidence\nIf 2-3 genuinely distinct searches return zero matching results or clearly unrelated papers, conclude via `conclude_search` and explicitly note the absence of literature in your summary. Do not exit after a single null result if a meaningfully different search angle remains untried.\n\n# Bounded Retrieval Rules\n\n- Strict Retrieval Tool Budget: You operate under a finite budget of retrieval tool calls (search_corpus, get_document_toc, read_document, get_related_items). \n - The system tracks your usage and alerts you in tool responses as you approach or reach the limit. \n - Termination tools (`conclude_search`, `request_search_extension`) are free: they do not consume your retrieval budget.\n - If essential facets remain unaddressed as your budget is depleted, you may request an extension (`request_search_extension`). \n- Budget is a ceiling, not a quota: Most targeted questions require only a handful of tool calls (e.g., 1 ToC lookup + 1 batched section read, or 1 search + 1 targeted read). Conclude once the search goal is thoroughly addressed.\n- Retrieved evidence is automatically accumulated in the background across all turns. Do not re-read assets or repeat searches. Redundant calls burn your tool budget without adding new evidence.\n\n# Termination Protocol - Mandatory Termination Contract\n\n- You MUST call `conclude_search` or `request_search_extension` to report what you found and what remains unaddressed or missing.\n- Your text output must NEVER contain a final answer, explanation, or synthesis of the research question. Writing answers is strictly prohibited and breaks pipeline role separation; the Literature Synthesizer handles the final response.\n- As soon as your planned retrieval actions are complete, call `conclude_search` or `request_search_extension` and stop.\n'
LIBRARY_SYNTHESIZER_AGENT_INSTRUCTION
module-attribute
¶
LIBRARY_SYNTHESIZER_AGENT_INSTRUCTION = synthesizer_instruction.format(attribution_via_citations=with_citations)
LIBRARY_SYNTHESIZER_AGENT_INSTRUCTION_STANDARD
module-attribute
¶
LIBRARY_SYNTHESIZER_AGENT_INSTRUCTION_STANDARD = synthesizer_instruction.format(attribution_via_citations=without_citations)
TEMP_EXTENSION_REQUEST_PASS
module-attribute
¶
TEMP_RETRIEVAL_TOOL_BUDGET
module-attribute
¶
TEMP_RETRIEVAL_TOOL_COUNT
module-attribute
¶
USER_RESEARCH_PROFILE_STR
module-attribute
¶
_auto_generate_completion_report ¶
Synthesize a completion report when conclude_search is not explicitly called.
Source code in zocrates/agents/library_search/search_pipeline.py
_clean_user_facing_synthesis ¶
Post-process synthesizer output to deterministically strip thinking tags, leaked internal keys, or chunk IDs.
Source code in zocrates/agents/library_search/search_pipeline.py
_enqueue_isolation_scope_closing_event
async
¶
Emit a terminal finish_task event that closes ctx's isolation scope.
ADK's Runner._find_active_task_scope treats any non-empty
isolation_scope as an unclosed in-flight task agent awaiting user input
unless an event carrying a finish_task FunctionResponse (result
"Task completed." or "Task failed.") is recorded for that scope.
library_search stamps the pipeline's events with
search_pipeline:{fc_id}, so without explicit closure ADK tags
subsequent user turns with the stale scope and the coordinator
(isolation_scope=None) drops them, leaving the coordinator stuck on the
first turn's prompt. Emitting the closing event on the invocation context
lets Runner._find_active_task_scope recognize the scope as finished.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The dynamically executed search pipeline context. |
required |
result
|
str
|
Terminal |
required |
Source code in zocrates/agents/library_search/search_pipeline.py
_ensure_isolation_scope ¶
Recover and assign isolation scope to ctx and its invocation context if unset.
Source code in zocrates/agents/library_search/search_pipeline.py
_get_applicable_cached_tocs ¶
Return formatted cached TOC outlines only if 100% of active items are cached.
If active items are empty (whole library search), or if ANY active item lacks a cached TOC, returns an empty list to prevent asymmetric cognitive bias.
Source code in zocrates/agents/library_search/search_pipeline.py
_get_pipeline_interrupt_ids ¶
Scan session events and ctx.resume_inputs to return set of all pipeline interrupt IDs.
_has_context_continuity ¶
Return True if prior turn and current turn share active context scope.
Source code in zocrates/agents/library_search/search_pipeline.py
_is_item_cached ¶
Check if item is cached. Primary: parent_key (input_key alias). Secondary: child attachments.
Source code in zocrates/agents/library_search/search_pipeline.py
_recover_isolation_scope ¶
Recover the search pipeline's isolation scope from snapshot or session events if unset.
Source code in zocrates/agents/library_search/search_pipeline.py
_resolve_cached_entry ¶
Resolve the cached TOC entry for an item, checking parent key then children.
Source code in zocrates/agents/library_search/search_pipeline.py
_rewrite_relative_markdown_images ¶
Rewrite any relative images/ Markdown image links to zocrates-img:// URIs.
Source code in zocrates/agents/library_search/search_pipeline.py
_run_search_pipeline
async
¶
Core search-pipeline body: subagent resolution, retrieval, rerank, and synthesis.
Source code in zocrates/agents/library_search/search_pipeline.py
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 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 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 | |
_strip_thinking_tags ¶
build_coordinator_view ¶
Build a clean, human-readable Markdown representation for the coordinator agent.
Substitutes in-text numeric chunk citation tokens ([1], [1, 2], etc.) with natural parenthetical author-year citations, masks code blocks, strips trailing HTML/reference blocks, and appends a clean Markdown two-tier bibliography without HTML tags or internal item keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Response text (may contain numeric citation tokens or existing sources). |
required |
citations
|
list[dict[str, Any]]
|
List of citation dicts containing metadata (index, authors, year, title). |
required |
references
|
list[dict[str, Any]]
|
List of reference dicts containing document metadata (tier, authors, year, title, publication). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Clean Markdown string with parenthetical citations and clean Markdown bibliography. |
Source code in zocrates/agents/library_search/citation_resolver.py
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 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 | |
coerce_to_text ¶
Extract plain text string from string, Content, Part, dict, Event, or object.
Extracts text parts while strictly suppressing reasoning/thought parts (where
thought=True) and placing parts extraction ahead of .text to prevent
internal thought tokens or raw object reprs from leaking into user-facing answers.
Source code in zocrates/agents/common/pipeline_base.py
conclude_search ¶
Conclude the retrieval phase and hand off accumulated evidence to the synthesizer.
Call this tool as soon as you have collected the necessary evidence, or immediately upon exhausting your retrieval tool budget. Do NOT write final answers or syntheses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
str
|
1-2 sentence overview of the evidence gathered. |
required |
notes
|
str | None
|
Optional observations regarding caveats or overall synthesis guidance. |
None
|
gaps
|
list[str] | None
|
Optional list of missing facets or literature gaps. If there are no gaps, leave this parameter unspecified. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Confirmation dictionary indicating search has concluded. |
Source code in zocrates/agents/common/tools.py
create_library_search_agent ¶
Create the stateless retrieval subagent equipped with the consolidated retrieval tool suite.
Source code in zocrates/agents/library_search/search_pipeline.py
create_library_synthesizer_agent ¶
create_library_synthesizer_agent(model=None, thinking_level='high', generate_content_config=None, citations_enabled=None)
Create the grounded literature synthesizer agent.
Source code in zocrates/agents/library_search/search_pipeline.py
enqueue_isolation_scope_closing_event
async
¶
Emit a terminal finish_task event that closes ctx's isolation scope.
ADK's Runner._find_active_task_scope treats any non-empty
isolation_scope as an unclosed in-flight task agent awaiting user input
unless an event carrying a finish_task FunctionResponse (result
"Task completed." or "Task failed.") is recorded for that scope.
Stamping the pipeline's events with an isolation scope without explicit closure
causes ADK to tag subsequent user turns with the stale scope, causing the coordinator
(isolation_scope=None) to drop them. Emitting the closing event on the
invocation context lets Runner._find_active_task_scope recognize the scope as finished.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The dynamically executed search pipeline context. |
required |
result
|
str
|
Terminal |
required |
default_author
|
str
|
Fallback author name if ctx.agent_name is unset. |
'search_pipeline_node'
|
Source code in zocrates/agents/common/pipeline_base.py
ensure_isolation_scope ¶
Recover and assign isolation scope to ctx and its invocation context if unset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
Workflow execution context. |
required |
prefixes
|
tuple[str, ...] | list[str] | str
|
Required tuple, list, or string of acceptable isolation scope prefix(es). |
required |
Source code in zocrates/agents/common/pipeline_base.py
filter_substantive_evidence ¶
Filter out non-substantive evidence chunks (frontmatter, TOC).
Fallback guard: If filtering yields 2 or fewer substantive chunks (regardless of whether any remain), returns the original chunks so the synthesizer is not starved of evidence. This preserves frontmatter chunks when there is not enough substantive content to stand on its own (e.g. the query only matched 1-2 real sections alongside a frontmatter hit).
Source code in zocrates/agents/common/reranker.py
format_active_items ¶
Format active context items from session state for insertion into agent prompts.
Supports a hierarchical format when a parent item has multiple converted attachments and/or child notes. When a parent has exactly one converted attachment and no notes the output is byte-identical to the legacy flat format so existing prompts and tests are unaffected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active_items
|
list[dict[str, Any]] | None
|
List of item dictionaries representing active selections in
Zotero UI. Each entry may optionally include a |
required |
include_keys
|
bool
|
Whether to include |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted multi-line Markdown string. |
Source code in zocrates/agents/common/prompts.py
format_retrieved_evidence_str ¶
Format accumulated evidence chunks into a clean XML-tagged block.
Suitable for passing into agent prompts or sufficiency evaluators.
Encloses chunks inside
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evidence_chunks
|
list[dict[str, Any]] | None
|
List of serialized evidence chunk dictionaries. |
required |
Returns:
| Type | Description |
|---|---|
str
|
XML string summarizing all retrieved evidence chunks. |
Source code in zocrates/agents/common/prompts.py
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 | |
get_agent_generate_content_config ¶
get_agent_generate_content_config(thinking_level=DEFAULT_THINKING_LEVEL, include_thoughts=True, thinking_budget=None, num_retries=None, zotero_data_dir=None, model=None)
Construct an ADK GenerateContentConfig with thinking/reasoning parameters.
Sets ADK's native thinking_config (for Google Gemini models) as well as http_options.extra_body (for LiteLLM / OpenRouter / OpenAI reasoning models) and http_options.retry_options for baked-in network retries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thinking_level
|
str | ThinkingLevel | None
|
Thinking level ('minimal', 'low', 'medium', 'high', or None/disabled). |
DEFAULT_THINKING_LEVEL
|
include_thoughts
|
bool
|
Whether thoughts are returned in the response stream. |
True
|
thinking_budget
|
int | None
|
Optional token budget for reasoning (int or None). |
None
|
num_retries
|
int | None
|
Optional maximum retry attempts for HTTP requests (defaults to llm_num_retries in config or DEFAULT_LLM_NUM_RETRIES = 4). |
None
|
zotero_data_dir
|
Path | str | None
|
Optional root Zotero data directory for loading config. |
None
|
model
|
str | Any | None
|
Optional model identifier or LLM instance to tailor reasoning schema and Ollama thinking gating. |
None
|
Returns:
| Type | Description |
|---|---|
GenerateContentConfig | None
|
Configured GenerateContentConfig, or None if thinking is disabled. |
Source code in zocrates/agents/common/config.py
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 | |
get_citations_enabled ¶
Return whether in-text citations are enabled from zocrates_config.json.
Source code in zocrates/config.py
get_document_toc ¶
Retrieve the Title, Abstract, Table of Contents, Figures, and Tables for a given item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Unique Zotero item key. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with 'status', 'item_key', and 'toc_content'. |
Source code in zocrates/agents/common/tools.py
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 | |
get_pipeline_interrupt_ids ¶
Scan session events and ctx.resume_inputs to return set of all pipeline interrupt IDs.
Source code in zocrates/agents/common/pipeline_base.py
get_related_items ¶
Retrieve all verified related papers for a given document from the knowledge graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Unique Zotero item or attachment key. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with status, item_key, total_count, and list of related items. |
get_synthesizer_instruction ¶
Return the synthesizer instruction tailored to citation configuration.
Source code in zocrates/agents/library_search/search_pipeline.py
load_zocrates_config ¶
Load the Zocrates config from the data directory.
If zotero_data_dir is None, attempts to obtain it from the active
LibrarySyncer service or the ZOTERO_DATA_DIR environment variable.
Returns config merged with standard defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | str | None
|
Root Zotero data directory. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Parsed JSON config dict merged with defaults. |
Source code in zocrates/config.py
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 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 | |
read_document ¶
Read full document Markdown or targeted sections, figures, or tables from the OKF bundle.
Accepts exact asset IDs from an item's TOC (e.g., 's1', 's2', 'f1', 't1'), 'abstract' (or 'summary') to read the document's abstract, a list of IDs, or fuzzy heading names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Unique Zotero item key. |
required |
asset_id
|
str | list[str] | None
|
Asset ID from TOC, list of asset IDs, or fuzzy heading string. If None (default), reads whole document paginated. |
None
|
page
|
int | None
|
1-indexed page number if content exceeds ~3,000 words. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with 'status', 'item_key', and list of 'assets'. |
Source code in zocrates/agents/common/tools.py
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 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 | |
recover_isolation_scope ¶
Recover the search pipeline's isolation scope from snapshot or session events if unset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
Workflow execution context. |
required |
prefixes
|
tuple[str, ...] | list[str] | str
|
Required tuple, list, or string of acceptable isolation scope prefix(es)
(e.g. |
required |
Source code in zocrates/agents/common/pipeline_base.py
request_search_extension ¶
Request permission from the user to extend the retrieval budget beyond the current limit.
Use this tool when evidence volume or retrieval tool budget is approaching its ceiling and crucial literature aspects or candidate papers remain unaddressed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
justification
|
str
|
Clear reason why additional retrieval calls or evidence capacity are needed. |
required |
covered_summary
|
str
|
Brief summary of the findings and evidence collected so far. |
required |
missing_aspects
|
list[str]
|
List of specific unaddressed aspects, papers, or topics still needed. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary confirming extension request registration and turn conclusion. |
Source code in zocrates/agents/common/tools.py
rerank_evidence
async
¶
Rerank candidate chunks using OpenRouter cross-encoder with budget trimming and fallback.
Source code in zocrates/agents/common/reranker.py
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 | |
resolve_zotero_data_dir ¶
Resolve the active Zotero data directory with auto-discovery fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | str | None
|
Explicit data directory path or None. |
None
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Resolved Path to the Zotero data directory, or None if not located. |
Source code in zocrates/config.py
search_budget_checkpoint
async
¶
Dynamic workflow checkpoint node yielding RequestInput to pause for human extension.
Source code in zocrates/agents/library_search/search_pipeline.py
search_corpus ¶
Hybrid (dense vector + FTS5 BM25) search over indexed library chunks with compound pre-filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The search query string. If empty, returns immediately. |
required |
item_key
|
str | list[str] | None
|
Scope of the search: - "active" (default): searches active context items selected in Zotero (or entire library if none selected). - None, "all", or "*": searches across the ENTIRE library (unfiltered). - Specific item key(s) (e.g. "HCZLU22L" or ["HCZLU22L", "M5Z7SFWM"]): filters strictly to those items. |
'active'
|
chunk_type
|
str | list[str] | None
|
Chunk type filter ('frontmatter', 'figure', 'table', 'equation', 'code', 'text'). Omit, None, or "all" to search across all chunk types. |
None
|
limit
|
int
|
Maximum number of chunks to return (default 10). |
10
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with 'status' and list of matching 'results'. |
Source code in zocrates/agents/common/tools.py
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 | |
search_library
async
¶
Autonomous search tool executing the local library search and synthesis pipeline.
Use this tool when the user asks questions about papers, notes, or topics contained in their existing Zotero library.
Source code in zocrates/agents/library_search/search_pipeline.py
search_library_pipeline_node
async
¶
Dynamic workflow function orchestrating autonomous search, reranking, and synthesis.
Wraps _run_search_pipeline in a try/finally so the node always closes
its isolation scope (search_library_pipeline:{fc_id}) before returning, whether
it succeeds ("Task completed.") or raises ("Task failed."). Closing the
scope prevents ADK's Runner from treating the finished pipeline as an
unclosed in-flight task agent and hijacking subsequent user turns.
Source code in zocrates/agents/library_search/search_pipeline.py
strip_snippet_keys ¶
Programmatically strip item key attributes from snippet XML tags.
Leaves all other XML attributes (e.g. paper, page, authors) and snippet text content intact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snippet_xml
|
str
|
XML-formatted snippet string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Snippet XML string with all ' key="..."' attributes removed. |