agentscope.pipelines.pipeline module
Base class for Pipeline
- class agentscope.pipelines.pipeline.PipelineBase[源代码]
基类:
Operator
Base interface of all pipelines.
The pipeline is a special kind of operator that includes multiple operators and the interaction logic among them.
- class agentscope.pipelines.pipeline.IfElsePipeline(condition_func: ~typing.Callable[[dict], bool], if_body_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator], else_body_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator] = <function placeholder>)[源代码]
基类:
PipelineBase
A template pipeline for implementing control flow like if-else.
IfElsePipeline(condition_func, if_body_operators, else_body_operators) represents the following workflow:
if condition_func(x): if_body_operators(x) else: else_body_operators(x)
- __init__(condition_func: ~typing.Callable[[dict], bool], if_body_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator], else_body_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator] = <function placeholder>) None [源代码]
Initialize an IfElsePipeline.
- 参数:
condition_func (Callable[[dict], bool]) – A function that determines whether to execute if_body_operators or else_body_operators based on the input x.
if_body_operators (Operators) – Operators executed when condition_func returns True.
else_body_operators (Operators) – Operators executed when condition_func returns False, does nothing and just return the input by default.
- class agentscope.pipelines.pipeline.SwitchPipeline(condition_func: ~typing.Callable[[dict], ~typing.Any], case_operators: ~typing.Mapping[~typing.Any, ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator]], default_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator] = <function placeholder>)[源代码]
基类:
PipelineBase
A template pipeline for implementing control flow like switch-case.
SwitchPipeline(condition_func, case_operators, default_operators) represents the following workflow:
switch condition_func(x): case k1: return case_operators[k1](x) case k2: return case_operators[k2](x) ... default: return default_operators(x)
- __init__(condition_func: ~typing.Callable[[dict], ~typing.Any], case_operators: ~typing.Mapping[~typing.Any, ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator]], default_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator] = <function placeholder>) None [源代码]
Initialize a SwitchPipeline.
- 参数:
condition_func (Callable[[dict], Any]) – A function that determines which case_operator to execute based on the input x.
case_operators (dict[Any, Operators]) – A dictionary containing multiple operators and their corresponding trigger conditions.
default_operators (Operators, defaults to placeholder) – Operators that are executed when the actual condition do not meet any of the case_operators, does nothing and just return the input by default.
- class agentscope.pipelines.pipeline.ForLoopPipeline(loop_body_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator], max_loop: int, break_func: ~typing.Callable[[dict], bool] = <function ForLoopPipeline.<lambda>>)[源代码]
基类:
PipelineBase
A template pipeline for implementing control flow like for-loop
ForLoopPipeline(loop_body_operators, max_loop) represents the following workflow:
for i in range(max_loop): x = loop_body_operators(x)
ForLoopPipeline(loop_body_operators, max_loop, break_func) represents the following workflow:
for i in range(max_loop): x = loop_body_operators(x) if break_func(x): break
- __init__(loop_body_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator], max_loop: int, break_func: ~typing.Callable[[dict], bool] = <function ForLoopPipeline.<lambda>>)[源代码]
Initialize a ForLoopPipeline.
- 参数:
loop_body_operators (Operators) – Operators executed as the body of the loop.
max_loop (int) – Maximum number of loop executions.
(`Callable[[dict] (break_func) –
bool]`
_ (defaults to `lambda) –
False`) – A function used to determine whether to break out of the loop based on the output of the loop_body_operators.
- class agentscope.pipelines.pipeline.WhileLoopPipeline(loop_body_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator], condition_func: ~typing.Callable[[int, dict], bool] = <function WhileLoopPipeline.<lambda>>)[源代码]
基类:
PipelineBase
A template pipeline for implementing control flow like while-loop
WhileLoopPipeline(loop_body_operators, condition_operator, condition_func) represents the following workflow:
i = 0 while (condition_func(i, x)) x = loop_body_operators(x) i += 1
- __init__(loop_body_operators: ~agentscope.agents.operator.Operator | ~typing.Sequence[~agentscope.agents.operator.Operator], condition_func: ~typing.Callable[[int, dict], bool] = <function WhileLoopPipeline.<lambda>>)[源代码]
Initialize a WhileLoopPipeline.
- 参数:
loop_body_operators (Operators) – Operators executed as the body of the loop.
(`Callable[[int (condition_func) –
dict]
bool]`
to (defaults)
_ (`lambda) –
False`): A function that determines whether to continue executing the loop body based on the current loop number and output of the loop_body_operator
__ – False`): A function that determines whether to continue executing the loop body based on the current loop number and output of the loop_body_operator
- class agentscope.pipelines.pipeline.SequentialPipeline(operators: Sequence[Operator])[源代码]
基类:
PipelineBase
A template pipeline for implementing sequential logic.
Sequential(operators) represents the following workflow:
x = operators[0](x) x = operators[1](x) ... x = operators[n](x)