evofabric.app.rethinker#
- evofabric.app.rethinker.list_ele_overwrite(old: list = MISSING, new: list = MISSING)#
Perform element-wise overwrite merge on a fixed-length list, adhering to the maximum parallel scale limit.
This function merges
oldandnewinto a result list, whose length is determined byconfig.structure.num_parallel. The merge rule is element-wise overwrite:If
oldis provided, first copy its elements to the result.If
newis provided, when the corresponding element innewis notNone, overwrite the element at the same position in the result.
- Parameters:
old (list) – Old State list; if
MISSING, ignore.new (list) – New State list; if
MISSING, ignore.
- Returns:
Element-wise overwritten list, length of
config.structure.num_parallel.- Return type:
list
- evofabric.app.rethinker.get_agent(client: ChatClientBase, finish_type: Literal['answer', 'select'])#
Build an Agent for encoding/inference based on configuration.
- Parameters:
client (ChatClientBase) – Chat client base class instance, used to interact with the model.
finish_type (Literal['answer', 'select']) – End type, used to specify the Agent’s completion method (e.g.,
'answer'or'select').
- Returns:
Built Agent object.
- Return type:
Any
- evofabric.app.rethinker.build_rethinker_graph()#
Build and configure a computation graph (Graph) supporting dynamic parallel structures.
This graph splits a single query into multiple parallel branches for generation, summarization, criticism, and filtering to obtain the best result. The overall structure includes:
Entry node
dispatch: Distributes the initial State to all parallel branches.- Parallel branches (number equals
config.structure.num_parallel): Each branch internally forms a serial pipeline: Solution phase: Cascaded
SolutionWithReThinkNodefor generating/improving candidate solutions.Summary phase: A
GuidedSummaryNodefor guided summarization of Solution outputs.Critic phase: Cascaded
CriticWithRethinkNodefor evaluating and critiquing the summary results with feedback.
- Parallel branches (number equals
Aggregation node
selector(ConfidenceGuideSelectNode): Receives outputs from the last critic node in each branch and selects the best final result.
- Returns:
The constructed computation graph object.
- Return type:
Any
- async evofabric.app.rethinker.run_rethinker_graph(query: str, query_id: str | None = None, semaphore: asyncio.Semaphore | None = None)#
Asynchronously run the rethinker execution graph to process a single query.
This function builds the rethinker computation graph, initializes log/output directories for each query, injects query metadata into the stream context, and executes the entire graph asynchronously.
When
config.exp.output_rootis set, output files are organized as follows:output_root/qid00001/node1.jsonnode2.json…
result.json
qid00002/…
- Parameters:
query (str) – Input query to be processed by rethinker graph.
query_id (Optional[str]) – Unique identifier for the query; automatically generated as UUID if not provided.
semaphore (Optional[asyncio.Semaphore]) – Semaphore for synchronization/limiting concurrent execution.
- Returns:
Final result returned by rethinker execution graph.
- Return type:
Any
- class evofabric.app.rethinker.LLMConfig#
Configuration model related to LLM calls, used to describe model name, authentication information, request parameters, and inference parameters.
- model_name#
LLM model name used.
- Type:
str
- api_key#
API Key typically required by OpenAI-compatible backends for authentication.
- Type:
str
- base_url#
Base URL for LLM API.
- Type:
str
- csb_token#
CSB authentication token, used for authorization via CSB Token.
- Type:
Optional[str]
- max_retries#
Maximum retry attempts for transient failure requests.
- Type:
int
- timeout#
Request timeout in seconds. If
None, use backend default.- Type:
Optional[int]
- top_p#
Nucleus Sampling parameter to control cumulative probability mass.
- Type:
Optional[float]
- temperature#
Sampling temperature to control randomness of generation results.
- Type:
Optional[float]
- max_tokens#
Maximum generated tokens; if
None, use backend default.- Type:
Optional[int]
- extra_body#
Additional backend-specific request body parameters.
- Type:
dict
- fast_think#
Whether to enable fast thinking mode: triggered by appending
/no_thinkto the last message.- Type:
bool
- output_logp#
Whether to return token-level log probabilities in the response.
- Type:
bool
- stop_condition#
Stop condition string for streaming output; generation terminates when this string is matched.
- Type:
Optional[str]
- http_client_kwargs#
Keyword arguments passed to the underlying OpenAI HTTP Client.
- Type:
Optional[dict]
- stream#
Whether to enable streaming output; must be True when
stop_conditionis set.- Type:
bool
- create_client_kwargs(self) dict#
Generate the parameter dictionary for initializing the underlying Client.
This method includes basic parameters such as
api_key,base_url,max_retries, andtimeout; whencsb_tokenis set, it appends thecsb-tokenheader todefault_headers.- Returns:
Client initialization parameter dictionary.
- Return type:
dict
- create_inference_kwargs(self) dict#
Generate the parameter dictionary for inference calls (Inference).
This method includes sampling parameters such as
temperatureandtop_p; whenextra_bodyis non-empty, it injectsextra_body; whenoutput_logpis True, it enableslogprobsand setstop_logprobs; whenmax_tokensis not None, it setsmax_tokens.- Returns:
Inference call parameter dictionary.
- Return type:
dict
- class evofabric.app.rethinker.WebParserConfig#
Webpage parsing configuration, used to control scraping, parsing, and content truncation strategies.
- llm_input_max_char#
After webpage parsing, the maximum character budget allowed for inputting a single document into the model.
- Type:
int
- model#
Name of the backend model used for webpage content parsing or downstream inference.
- Type:
str
- use_jina#
Whether to enable Jina-based webpage content parsing.
- Type:
bool
- jina_api_key#
Jina service API Key; typically required when
use_jinais enabled.- Type:
Optional[str]
- ssl_verify#
Whether to verify SSL certificates when making HTTP requests.
- Type:
bool
- timeout#
Network request timeout (seconds) for fetching web page content.
- Type:
int
- show_url_content_max_char#
Maximum number of characters allowed per URL; negative values exclude URL content.
- Type:
int
- class evofabric.app.rethinker.WebSearchConfig#
Web search configuration for controlling authentication and request behavior of the retrieval service.
- serper_api_key#
Serper service API Key; used to enable web search requests.
- Type:
Optional[str]
- retries#
Maximum number of retries when a web search request fails.
- Type:
int
- ssl_verify#
Whether to verify SSL certificates during web search HTTP requests.
- Type:
bool
- timeout#
Request timeout (seconds) for a single web search call.
- Type:
int
- class evofabric.app.rethinker.SolutionConfig#
Problem-solving/reasoning phase configuration, including model and rule settings for stages such as solution generation, reflection, summarization, and selection.
- solver_model#
LLM backend model used in the solution generation phase.
- Type:
str
- critic_model#
LLM backend model used in the critic evaluation phase.
- Type:
str
- summary_model#
LLM backend model used in the guided summaries phase.
- Type:
str
- selector_model#
LLM backend model used in the selection phase.
- Type:
str
- selector_iteration#
Number of iterations in the selection phase, used for gradual convergence and optimization of selection results.
- Type:
int
- stop_condition#
Regular expression pattern used to extract code blocks from LLM outputs.
- Type:
str
- selection_condition#
Regular expression pattern used to extract the selected response index from LLM outputs.
- Type:
str
- answer_condition#
Regular expression pattern for extracting final answer content from LLM output.
- Type:
str
- max_agent_step#
Maximum number of reasoning/action steps allowed per agent execution.
- Type:
int
- tool_timeout#
Timeout duration (in seconds) for calling a single tool or external service.
- Type:
int
- max_empty_response#
Maximum allowed consecutive empty responses; agent execution will terminate upon exceeding this limit.
- Type:
int
- chat_template#
Multi-turn dialogue serialization template string; used solely for serialization, not as an LLM prompt.
- Type:
Optional[str]
- class evofabric.app.rethinker.ExpConfig#
Experimental configuration, including dataset input, output directory, and concurrency limits.
- input_file_path#
File path of the input dataset used for the experiment.
- Type:
str
- exp_name#
Experiment name, typically used as a subdirectory name under the output root directory.
- Type:
str
- output_root#
Output root directory; if
None, no cache or output will be written.- Type:
Optional[str]
- max_question_thread_limit#
Maximum number of concurrent problems allowed for execution.
- Type:
int
- max_node_thread_limit#
Maximum number of concurrent nodes allowed during execution.
- Type:
int
- class evofabric.app.rethinker.StructureConfig#
Reasoning structure configuration, used to control parallel candidate count and iteration counts per phase.
- num_parallel#
Number of solution candidates generated in parallel per task.
- Type:
int
- num_solution_iteration#
Iteration count for generating each candidate solution.
- Type:
int
- num_critic_iteration#
Iteration count for the Guided reflection phase.
- Type:
int
- class evofabric.app.rethinker.PromptConfig#
Prompt template configuration, centrally managing prompts for parsing, solving, reflection, summarization, and selection stages.
- web_parser_pdf#
Prompt template for parsing PDF webpage content.
- Type:
str
- web_parser_html#
Prompt template for parsing HTML webpage content.
- Type:
str
- solver_user_prompt#
User prompt template for the initial problem-solving stage.
- Type:
str
- solver_twice_user_prompt#
User prompt template for secondary problem-solving (second-pass solution generation).
- Type:
str
- critic_user_prompt#
User prompt template for the initial reflection stage.
- Type:
str
- critic_twice_user_prompt#
User prompt template for secondary reflection (second-pass critique/evaluation).
- Type:
str
- guided_summary_prompt#
Prompt template for guided summaries.
- Type:
str
- selector_user_prompt#
User prompt template for the selection stage.
- Type:
str
- selector_iteration_user_prompt#
Iterative selection refinement user prompt template.
- Type:
str
- class evofabric.app.rethinker.GraphConfig#
Execution Graph (Graph) overall configuration, aggregating LLM resources, web parsing/search, problem-solving stages, structural parameters, experimental parameters, and prompt templates.
- llm_resources#
Dictionary of available LLM backend resources; keys are model names, values are corresponding
LLMConfigconfiguration objects.- Type:
dict[str, LLMConfig]
- web_parser#
Web content parsing configuration.
- Type:
- web_search#
Web search configuration.
- Type:
- solution#
Configuration set for the solution, reflection, summary, and selection phases.
- Type:
- structure#
Iterative reasoning graph structure configuration, including parallelism and selector behavior.
- Type:
- exp#
Experimental-level configuration, including I/O paths, output directory, and thread limits.
- Type:
- prompts#
Collection of prompt templates used throughout the experiment (parsing, solving, reflection, selection, etc.).
- Type:
- class evofabric.app.rethinker.Config#
Experiment configuration manager.
This class is responsible for loading and accessing the complete experiment configuration: it supports loading from YAML files as well as directly loading a
GraphConfiginstance. It provides convenient access to sub-configurations (LLM resources, web parsing/search, solution settings, structure, experiment I/O, prompts, etc.) and maintains a global semaphore to control node-level concurrency during execution.- property graph#
Obtain the complete
GraphConfigconfiguration object (configuration must be loaded first).- Returns:
Currently loaded graph configuration.
- Return type:
- property llm_resources#
Obtain LLM backend resource configuration (configuration must be loaded first).
- Returns:
LLM Resource Dictionary.
- Return type:
dict[str, LLMConfig]
- property web_parser#
Get Web Parsing Configuration (Configuration must be loaded first).
- Returns:
Web Parsing Configuration Object.
- Return type:
- property web_search#
Get Web Search Configuration (Configuration must be loaded first).
- Returns:
Web Search Configuration Object.
- Return type:
- property solution#
Get Problem-Solving Phase Configuration (Configuration must be loaded first).
- Returns:
Problem-Solving Phase Configuration Object.
- Return type:
- property structure#
Get Structure Configuration (Configuration must be loaded first).
- Returns:
Structure Configuration Object.
- Return type:
- property exp#
Get Experimental-Level Configuration (Configuration must be loaded first).
- Returns:
Experimental-Level Configuration Object.
- Return type:
- property prompts#
Get Prompt Template Configuration (Configuration must be loaded first).
- Returns:
Prompt Template Configuration Object.
- Return type:
- load(self, config_path: str | Path) None#
Load Experimental Configuration from YAML File.
- Parameters:
config_path (Union[str, Path]) – YAML Configuration File Path.
- Raises:
FileNotFoundError – Raised when the configuration file does not exist.
- loads(self, config: GraphConfig) None#
Load experiment configuration from an existing
GraphConfiginstance.- Parameters:
config (GraphConfig) – Pre-constructed
GraphConfiginstance.
- get_semaphore(self) asyncio.Semaphore#
Obtain the global semaphore for node-level concurrency control.
If not initialized, creates and caches an
asyncio.Semaphorebased onexp.max_node_thread_limit.- Returns:
asyncio.Semaphoreobject limiting concurrent node execution.- Return type:
asyncio.Semaphore
- evofabric.app.rethinker.config#
Global singleton configuration manager instance for loading and accessing experiment configurations.
- Type:
- evofabric.app.rethinker.repeat_prompt(prompt: str, repeat_time: int = 3) str#
Repeat the given prompt text a specified number of times, inserting a fixed English transition prompt between repetitions.
- Parameters:
prompt (str) – Prompt text to be repeated.
repeat_time (int, optional) – Repeat count, must be greater than or equal to 1, default is
3.
- Raises:
ValueError – Raise an exception when
repeat_time < 1.- Returns:
Complete prompt string after concatenation, with paragraphs separated by two line breaks.
- Return type:
str
- evofabric.app.rethinker.generate_stop_condition(pattern: str)#
Generate a “streaming stop condition” function based on the given regular expression pattern.
The generated stop condition function uses
re.finditer(withre.DOTALL) to match streaming content; once at least one match is detected, it returnsTrueto indicate that generation/parsing should stop.- Parameters:
pattern (str) – The regular expression pattern used to match streaming content.
- Returns:
A stop condition function. The function signature is
(content: str) -> bool, returningTruewhen a match is detected.- Return type:
callable
- class evofabric.app.rethinker.FastSlowThinkOpenAIChatClient#
An OpenAI Chat Client extension implementation supporting “fast thinking” mode.
When
fast_thinkis enabled,/no_thinkis appended to thecontentof the last input message to trigger the backend’s fast mode (skipping or reducing reasoning output).- fast_think#
Whether to enable fast thinking mode.
- Type:
bool
- evofabric.app.rethinker.get_client(model: str)#
Retrieves an OpenAI Chat Client instance corresponding to a specified model name.
This function looks up the corresponding
LLMConfigfrom the global configuration’sllm_resources, then constructs initialization parameters forFastSlowThinkOpenAIChatClient(model name, streaming flag, client parameters, reasoning parameters, etc.). If the configuration containsstop_condition, it additionally injectsstream_parserto allow early termination during streaming parsing based on the stop condition.- Parameters:
model (str) – Model identifier name (used to retrieve from the LLM resources dictionary in the configuration).
- Raises:
ValueError – Raises an exception when
modelis not found in the configured LLM resources.- Returns:
The Chat Client instance corresponding to the model.
- Return type:
- class evofabric.app.rethinker.CodingAgentResult#
The execution result data model for encoding/reasoning agents.
This result object summarizes context information, step count, duration, full conversation logs, raw client responses per round, and (optionally) the final rendered output text from a single agent execution.
- total_steps#
Total steps of reasoning/actions completed by the agent before termination.
- Type:
int
- generation_time#
End-to-end execution time of the agent (seconds), including LLM and tool calls.
- Type:
float
- agent_logs#
Full conversation trajectory log maintained by the agent.
- Type:
list
- client_responses#
List of raw responses returned by the LLM client for each iteration.
- Type:
list
- response#
Final output text rendered from the agent log using the configured chat template.
If no chat template is provided, this field is
None.- Type:
Optional[str]
- class evofabric.app.rethinker.CodingAgent#
A LLM-driven autonomous coding agent supporting multi-step iterative reasoning and native Python code execution.
This agent maintains the full conversation trajectory and repeatedly executes the following process until termination conditions are met:
Invoke LLM backend to generate response;
Parse structured signals (e.g., code blocks or final answers) from model output;
Execute generated Python code via the user-provided executor;
Inject execution results back into the conversation context.
Main capabilities include:
Configurable multi-step iterative reasoning (maximum steps configurable)
Structured extraction and execution of “tool content (Python code)”
Automatic fallback prompt usage to conclude when model output is empty or invalid
Final answer detection based on regular expression patterns
Detailed step-by-step logging and execution tracking
This agent is designed to be used as an asynchronous callable node within a larger execution graph/workflow system.
- client#
LLM conversation client used to initiate generation requests at each agent step.
- Type:
- max_agent_step#
Maximum number of reasoning/action steps allowed for the agent.
- Type:
int
- max_empty_response#
Maximum allowed consecutive empty responses.
“Empty response” refers to output that matches neither the code pattern nor the answer pattern.
- Type:
int
- tool_timeout#
Timeout for tool (Python code) execution (seconds).
- Type:
int
- force_finish_prompt_candidates#
List of fallback prompt candidates used when the agent produces an empty response to prompt the model to provide a final answer and conclude the conversation.
- Type:
list
- tool_content_pattern#
Regular expression pattern used to extract tool content (code) from agent responses.
- Type:
str
- answer_pattern#
Regular expression pattern used to extract final answer content from agent responses.
- Type:
str
- chat_template#
Chat template for formatting agent interaction history into a single string.
If
None, the final renderedresponsefield will not be output.- Type:
str
- py_exec_handler#
Processing function for executing generated Python code, typically taking
(code: str, timeout: int)as input and asynchronously returning an execution result object.- Type:
Callable[[str, int], Awaitable[BaseModel]]
- async __call__(self, prompt: str) CodingAgentResult#
Run the coding agent with a single input prompt.
This method writes the
promptas the first user message in the internal conversation history, then begins subsequent reasoning, tool extraction and execution, result injection, until the termination condition is met.- Parameters:
prompt (str) – Initial user prompt provided to the agent, serving as the starting point for the entire conversation and reasoning process.
- Returns:
Structured agent execution result object containing execution context, step count, duration, full logs, raw responses per round, and optionally the final rendered output.
- Return type:
- class evofabric.app.rethinker.AsyncNodeWithCacheAndConcurrencyLimit#
Asynchronous node base class with built-in caching and concurrency control capabilities.
This class wraps two general capabilities around node execution:
Caching mechanism: Avoids redundant computation by reusing previously persisted results.
Concurrency limit: Controls the maximum number of concurrently executing nodes using a global semaphore.
Subclasses should implement the
_runmethod to define actual node logic; this logic itself does not need to concern itself with caching and concurrency control.- agent#
Coding agent instance, optionally used to complete tasks through multi-round iterative execution of Python code.
- Type:
Optional[CodingAgent]
- cache_dir_key#
The field name (key) used in
stateto retrieve the cache directory path.If the cache directory corresponding to this field can be obtained from
state, disk cache will be enabled; default value is"cache_dir".- Type:
Optional[str]
- async __call__(self, state: State) StateDelta#
Execute the node under cache and concurrency control protection.
Execution flow as follows:
Acquire the global semaphore and enter the asynchronous context to enforce concurrency limits.
If
cache_dir_keyexists and the cache directory can be retrieved fromstate: - Construct the cache file path based on the current node name (<node_name>.json); - If the cache file exists, load and return the cached result directly; - Otherwise, execute_run, write the result to the cache file, and return.If cache cannot be enabled (not configured or cache directory cannot be retrieved from
state), directly execute_runand return the result.
- Parameters:
state (State) – The current execution state object.
- Returns:
The state delta (or equivalent change result) produced by this node.
- Return type:
StateDelta
- async _run(self, state: State) StateDelta#
Core logic for executing the node (implemented by subclasses).
This method contains only the actual computation or model invocation logic, without handling cache or concurrency control. The base class implementation will directly raise
NotImplementedErrorto indicate that it must be overridden by subclasses.- Parameters:
state (State) – The current execution state object.
- Raises:
NotImplementedError – Exception raised when the subclass does not implement this method.
- Returns:
The state delta (or equivalent change result) produced by this node.
- Return type:
StateDelta
- class evofabric.app.rethinker.SolutionWithReThinkNode#
A problem-solving node implementation supporting “revisit/rethink (ReThink)”, inheriting from
AsyncNodeWithCacheAndConcurrencyLimit.This node determines the prompt generation method based on whether
last_roundis provided:When
last_roundis empty, indicating the first round of problem-solving, the prompt is constructed usingconfig.prompts.solver_user_prompt.When
last_roundis non-empty, extract the response content at the specifiedindexfrom the previous round’s results, parse it, and inject it intoconfig.prompts.solver_twice_user_promptfor secondary solving/rethinking.
The final result will be written to the field corresponding to
output_keyin the form of a parallel slot list after invoking theagentto execute the prompt.- last_round#
Indicates the key for retrieving the previous round’s answer from which round’s results.
If
None: indicates the first round, no rethinking is performed;If not
None: indicates retrieving the previous round’s answer fromstate[last_round]and performing rethinking.
- Type:
Optional[str]
- output_key#
The storage key for the output result in the state increment, default value:
"solution".- Type:
str
- async _run(self, state: State) StateDelta#
Executes the problem-solving (or rethinking) logic and returns the state increment.
Execution points:
Read
queryandindexfromstate;If it is the first round (
last_roundis empty), construct the initial problem-solving prompt;If it is a rethinking round (
last_roundis non-empty), extract theresponseat the currentindexfrom the previous round’s results, parse it, and inject it into the secondary problem-solving prompt template;Invoke the
agentto asynchronously generate the result;Construct a list of length
config.structure.num_parallel, placing the current result only at positionindex, and return it in the form of{output_key: solution}.
- Parameters:
state (State) – The current execution state object.
- Returns:
Contains the state increment output by this node, with key
output_keyand value as a parallel slot list.- Return type:
StateDelta
- class evofabric.app.rethinker.CriticWithRethinkNode#
Implements a reflection (Critic) node supporting “review/rethinking (ReThink)”, inheriting from
AsyncNodeWithCacheAndConcurrencyLimit.This node is used for critical reflection/reflection on the solution results of a round, and optionally for secondary reflection/rethinking based on the results of the previous round:
Extract the content to be reflected from the State field specified by
input_key;After cleaning the content (removing thinking/execution fragments, etc.), inject the reflection prompt template;
If
last_roundis empty, use the initial reflection promptconfig.prompts.critic_user_prompt; otherwise, read the previous round’s reflection result, trim it, and inject the secondary reflection promptconfig.prompts.critic_twice_user_prompt;Call
agentto obtain the reflection output and write it as a parallel slot list tooutput_key.
- input_key#
The key for reading the content that needs to be reflected/criticized from the State.
- Type:
Optional[str]
- last_round#
The key where the previous round’s reflection result is stored.
If
None: indicates the first round of reflection, no rethinking is performed;If not
None: indicates reading the reflection result of the specified round and performing secondary reflection/rethinking.
- Type:
Optional[str]
- output_key#
The key for storing the reflection (or secondary reflection/rethinking) result in the State increment.
- Type:
Optional[str]
- async _run(self, state: State) StateDelta#
Execute the reflection (or secondary reflection/rethinking) logic and return the State increment.
Execution points:
Read
queryandindexfromstate;Read the solution output to be reflected from
state[input_key][index]["response"]and clean it;If
last_roundisNone, construct the initial reflection prompt;Otherwise, read
state[last_round][index]["response"]as the previous round’s reflection result, parse and trim it, then inject the secondary reflection prompt;Call
agentto asynchronously generate the reflection result.Construct a list of length
config.structure.num_parallel, placing only the current reflection result in theindexslot, and return in the form of{output_key: critic}.
- Parameters:
state (State) – The current execution state object.
- Returns:
Contains the State increment of the current node’s reflection output, with key
output_keyand value as a list of parallel slots.- Return type:
StateDelta
- class evofabric.app.rethinker.ConfidenceGuideSelectNode#
Implements a confidence-guided selection node, inheriting from
AsyncNodeWithCacheAndConcurrencyLimit.This node is used for selecting among multiple candidate responses and maintaining the full selection history. The overall process typically includes:
Read the candidate result list from
input_keyand parse the answer for each candidate;Construct a Latin square based on the number of candidates to organize the comparison/selection order;
Execute the initialization selection process (
_init_select) and iterative selection process (_iterative_select);Aggregate historical selection results to extract the candidate set with the highest votes/rank;
If multiple candidates are tied, enter the final selection process (
_final_select) to determine a single result;Write the selection history, final selected result, and candidate list to
output_key.
- input_key#
Key for reading the candidate solutions (or intermediate results) list from State, used for subsequent selection.
- Type:
Optional[str]
- output_key#
Storage key for selection results in State increment, default value
"selector".- Type:
str
- repeat_prompt#
Prompt repetition count configuration (used to control the repetition/emphasis level of prompts during the selection phase).
- Type:
int
- async _run(self, state: State) StateDelta#
Execute the candidate result selection process and return the State increment.
Execution points:
Read
queryfromstate;Read the candidate list from
state[input_key], and parse each candidate’sresponseinto pure answer text;Construct a Latin square based on the number of candidates to organize the comparison/selection order;
Execute initial selection and iterative selection sequentially, accumulating
_response_history;Calculate the top-ranked candidate set from the current selection history: if the candidate set size is greater than 1, perform final selection to obtain a single result;
Return a dictionary with key
output_key, whose value contains:selection_history(selection history),selected_response(final selected response), andresponse_list(candidate answer list).
- Parameters:
state (State) – The current execution state object.
- Returns:
Include the selection result as a State increment with key
output_key.- Return type:
StateDelta
- class evofabric.app.rethinker.GuidedSummaryNode#
Implementation of the Guided summary node, inheriting from
AsyncNodeWithCacheAndConcurrencyLimit.This node is used to generate “Guided summary” for candidate solutions:
Read the solution output to be summarized from the State field specified by
input_key;Clean the output content (remove unnecessary response structures/markers, etc.);
Construct the summary prompt using
config.prompts.guided_summary_prompt;Initiate a conversation generation request via
clientto obtain the summary content;Write the summary result as a parallel slot list to
output_key.
- client#
LLM dialogue client used for generating summary content.
- Type:
- input_key#
Key for reading content to be summarized from State.
- Type:
str
- output_key#
The storage key for the generated summary result in the State increment.
- Type:
str
- async _run(self, state: State) StateDelta#
Generate Guided reflection summary and return State increment.
Execution points:
Read
queryandindexfromstate;Read the content to be summarized from
state[input_key][index]["response"]and clean it;Inject the question and answer into the
guided_summary_prompttemplate to construct the prompt;Call
client.createto generate the summary, and organize the returned content into a dictionary structure: whereresponse["response"]will be set toresponse["content"]to unify field naming;Construct a list of length
config.structure.num_parallel, writing only the summary result to theindexslot;Return in the form of
{output_key: solution_summary}.
- Parameters:
state (State) – The current execution state object.
- Returns:
The State increment containing the summary result, with key
output_keyand value as a list of parallel slots.- Return type:
StateDelta
- class evofabric.app.rethinker.DispatchNode#
Synchronous distribution node, used as a placeholder or distribution entry node in the execution graph.
The current implementation of
__call__does not modify the State, directly returning an empty State increment.- __call__(self, state: State) StateDelta#
Execute distribution node logic and return State increment.
- Parameters:
state (State) – The current execution state object.
- Returns:
Empty State increment dictionary.
- Return type:
StateDelta
- evofabric.app.rethinker.get_dispatch_filter(index: int)#
Generate a distribution filter function for setting
state.index.The returned filter function sets the
indexfield of the incomingstateto the specified value and returns the updatedstate, commonly used to distribute parallel tasks to different slot indices.- Parameters:
index (int) – The index value to be written to
state.index.- Returns:
A filter function with signature
(state: State) -> State.- Return type:
callable
- class evofabric.app.rethinker.BaseBenchmarkEvaluator#
Abstract base class for benchmark evaluation.
This class provides a general evaluation pipeline covering data and result matching, parallel evaluation, exception handling, and statistical aggregation and storage. Subclasses must implement the
evaluate_itemmethod to define the specific benchmark evaluation logic.- data_file#
Source dataset file path (JSON).
- Type:
Path
- result_root#
Root directory where model generation results are stored.
- Type:
Path
- max_workers#
Maximum number of threads for parallel evaluation.
- Type:
int
- max_char#
Maximum number of characters to retain in the response text injected into the judge prompt (for truncation).
- Type:
int
- max_completion_tokens#
Maximum number of tokens allowed in the judge model’s output.
- Type:
int
- save_path#
Path to save evaluation results.
- Type:
Path
- result_extractor#
Optional result extraction function, used to extract model predictions from a single question directory.
If
None, default extraction logic is used; this field is excluded from serialization (functions are not serializable).- Type:
Optional[Callable[[str], Optional[str]]]
- model_post_init(self, __context: Any) None#
Hook method after model initialization, used to complete runtime initialization and validation.
This method will:
Create and cache the OpenAI client for judging;
Validate whether the data file exists (throw an exception if it does not exist);
Check if the result root directory exists (log a warning if it does not exist);
If
result_extractoris not provided, set it to the default extraction logic.
- Parameters:
__context (Any) – Context object passed via Pydantic.
- Raises:
FileNotFoundError – Throw an exception when
data_filedoes not exist.
- evaluate_item(self, data: Dict) Dict#
Evaluate a single sample (to be implemented by subclasses).
Subclasses must override this method to implement specific benchmark data scoring rules and metadata organization methods.
- Parameters:
data (Dict) – A single data sample, typically containing fields such as question, standard answer, and model prediction.
- Returns:
Evaluation result dictionary for a single sample, typically containing fields such as
scoreanddetails.- Return type:
Dict
- run(self)#
Run the complete benchmark evaluation process.
This method first matches source data with generated results, then uses a thread pool to evaluate all samples in parallel, and finally aggregates the results statistically and writes them to
save_path.- Returns:
No return value.
- Return type:
None
- class evofabric.app.rethinker.HLEEvaluator#
HLE Benchmark Evaluator, implements single-sample evaluation logic for HLE scenarios.
- evaluate_item(self, data: Dict) Dict#
Evaluates a single HLE sample.
This implementation constructs a judge prompt and uses a judge model for structured parsing, calculating the score based on the
correctfield in the parsing result.- Parameters:
data (Dict) – A single data sample containing fields such as
question,answer, andprediction.- Returns:
Evaluation result dictionary containing
score,error, anddetails.- Return type:
Dict
- Raises:
ValueError – Throws an exception when the structured parsing result from the judge model is empty.
- class evofabric.app.rethinker.XBenchEvaluator#
XBench Benchmark Evaluator, implements single-sample evaluation logic for XBench scenarios.
- evaluate_item(self, data: Dict) Dict#
Evaluates a single XBench sample.
This implementation calls the judge model to generate judgment text, extracts the “Conclusion (Correct/Incorrect)” field via regular expression, and then calculates the score.
- Parameters:
data (Dict) – A single data sample containing fields such as
question,answer, andprediction.- Returns:
Evaluation result dictionary containing
score,error, anddetails.- Return type:
Dict
- Raises:
ValueError – Throws an exception when the conclusion cannot be parsed from the judge output.
- class evofabric.app.rethinker.GaiaEvaluator#
GAIA Benchmark Evaluator, implements single-sample evaluation logic for GAIA scenarios.
- evaluate_item(self, data: Dict) Dict#
Evaluates a single GAIA sample.
This implementation constructs a judge prompt, calls the judge model to generate judgment results, normalizes the output content, and uses
correct/ non-correctas the scoring criterion.- Parameters:
data (Dict) – A single data sample containing fields such as
question,answer, andprediction.- Returns:
Evaluation result dictionary containing
score,error, anddetails.- Return type:
Dict
- async evofabric.app.rethinker.execute_python_code(code: str, timeout: int = 300) CodeResponse#
Asynchronously executes a Python code snippet and returns structured execution results.
This function delegates the actual code execution to a thread pool executor (via the event loop’s
run_in_executor), tracks execution time; if an exception occurs during execution, it logs the error and returns the error information in the result.- Parameters:
code (str) – Python code string to be executed.
timeout (int, optional) – Execution timeout in seconds, default
300.
- Returns:
Result object of code execution, containing standard output, error messages, and execution duration.
- Return type:
CodeResponse
- async evofabric.app.rethinker.web_parse(link: str, query: str) Dict[str, Any]#
Unified entry point for web content parsing.
This function dynamically selects an appropriate parser based on the input URL, executes the corresponding parsing logic, and returns the structured parsing result. If an unhandled exception occurs during parsing, it logs the error and returns a standardized error result dictionary.
- Parameters:
link (str) – URL of the web page to be parsed.
query (str) – Retrieval/question text in the parsing context, used to extract information related to this context from the page.
- Returns:
Parsing result dictionary, typically containing fields such as parsed content (content), related URL list (urls), and score; if an unhandled exception occurs, returns an error dictionary in the form
{"content": "System error during parsing"}.- Return type:
Dict[str, Any]
- async evofabric.app.rethinker.web_search(query: str, top_k: int = 10) Dict[str, Any] | List[Any]#
Search the internet using a search engine and return results.
This function constructs the required payload and headers, calls the Serper API for searching, and uses a retry mechanism to improve stability. On success, it typically returns a result dictionary containing the
organicfield; if retries ultimately returnNone, it returns an empty list.- Parameters:
query (str) – Search query string to be submitted.
top_k (int, optional) – Maximum number of returned results, default
10.
- Returns:
Returns a dictionary containing search results on success (typically results under the
organickey); if the request fails and retries yield no results, returns an empty list.- Return type:
Union[Dict[str, Any], List[Any]]
- evofabric.app.rethinker.download_and_read_pdf(url: str) str#
Synchronously download a PDF from a specified URL and extract its text content.
This function supports both direct PDF links and arXiv abstract page links (which are converted to direct PDF download links). After downloading, it uses PyMuPDF (fitz) to parse the PDF and extract all text.
- Parameters:
url (str) – The URL of a PDF file, or the arXiv abstract page URL (e.g.,
https://arxiv.org/abs/2106.07682).- Returns:
On success, return the extracted PDF text content; on failure, return a descriptive error string (e.g., ‘Failed to read the PDF’).
- Return type:
str