Skip to content

Commit

Permalink
fix pipeline tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-x-c committed Jan 19, 2024
1 parent 340f24d commit 35e8a4c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
2 changes: 2 additions & 0 deletions docs/sphinx_doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ AgentScope Documentation
.. toctree::
:maxdepth: 2
:glob:
:hidden:
:caption: AgentScope API Reference

agentscope.agents
Expand All @@ -38,6 +39,7 @@ AgentScope Documentation
agentscope.utils
agentscope.web_ui
agentscope

Indices and tables
==================

Expand Down
3 changes: 0 additions & 3 deletions docs/sphinx_doc/source/tutorial/main.md

This file was deleted.

47 changes: 23 additions & 24 deletions docs/tutorial/202-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is the base class for all pipeline types:

```python
class PipelineBase(Operator):
"""Base interface of all pipelines."""
"""Base interface of all pipelines."""
# ... [code omitted for brevity]
@abstractmethod
def __call__(self, x: Optional[dict] = None) -> dict:
Expand Down Expand Up @@ -47,7 +47,7 @@ AgentScope provides two main types of pipelines based on their implementation st

```python
# Just invoke
x = funcpipeline(x, agent1, agent2, agent3)
x = funcpipeline(agent1, agent2, agent3, x)
```

Pipelines are categorized based on their functionality, much like programming language constructs. The table below outlines the different pipelines available in AgentScope:
Expand All @@ -65,19 +65,19 @@ Pipelines are categorized based on their functionality, much like programming la

This section illustrates how pipelines can simplify the implementation of logic in multi-agent applications by comparing the usage of pipelines versus approaches without pipelines.

**Note:** Please note that in the examples provided below, we use the term `agent` to represent any instance that can act as an `_Operator`. This is for ease of understanding and to illustrate how pipelines orchestrate interactions between different operations. You can replace `agent` with any `_Operator`, thus allowing for a mix of `agent` and `pipeline` in practice.
**Note:** Please note that in the examples provided below, we use the term `agent` to represent any instance that can act as an `Operator`. This is for ease of understanding and to illustrate how pipelines orchestrate interactions between different operations. You can replace `agent` with any `Operator`, thus allowing for a mix of `agent` and `pipeline` in practice.

#### `SequentialPipeline`

* Without pipeline:

```
```python
x = agent1(x)
x = agent2(x)
x = agent3(x)
```

- Using pipeline:
* Using pipeline:

```python
from agentscope.pipelines import SequentialPipeline
Expand All @@ -86,12 +86,12 @@ This section illustrates how pipelines can simplify the implementation of logic
x = pipe(x)
```

- Using functional pipeline:
* Using functional pipeline:

```python
from agentscope.pipelines import sequentialpipeline

x = sequentialpipeline(x, [agent1, agent2, agent3])
x = sequentialpipeline([agent1, agent2, agent3], x)
```

#### `IfElsePipeline`
Expand All @@ -105,7 +105,7 @@ This section illustrates how pipelines can simplify the implementation of logic
x = agent2(x)
```

- Using pipeline:
* Using pipeline:

```python
from agentscope.pipelines import IfElsePipeline
Expand All @@ -114,12 +114,12 @@ This section illustrates how pipelines can simplify the implementation of logic
x = pipe(x)
```

- Using functional pipeline:
* Using functional pipeline:

```python
from agentscope.functional import ifelsepipeline

x = ifelsepipeline(x, condition, agent1, agent2)
x = ifelsepipeline(condition, agent1, agent2, x)
```

#### `SwitchPipeline`
Expand All @@ -136,7 +136,7 @@ This section illustrates how pipelines can simplify the implementation of logic
x = default_agent(x)
```

- Using pipeline:
* Using pipeline:

```python
from agentscope.pipelines import SwitchPipeline
Expand All @@ -146,13 +146,13 @@ This section illustrates how pipelines can simplify the implementation of logic
x = pipe(x)
```

- Using functional pipeline:
* Using functional pipeline:

```python
from agentscope.functional import switchpipeline

case_operators = {case1: agent1, case2: agent2}
x = switchpipeline(x, condition, case_operators, default_agent)
x = switchpipeline(condition, case_operators, default_agent, x)
```

#### `ForLoopPipeline`
Expand Down Expand Up @@ -180,19 +180,19 @@ This section illustrates how pipelines can simplify the implementation of logic
```python
from agentscope.functional import forlooppipeline

x = forlooppipeline(x, agent, max_iterations, break_condition)
x = forlooppipeline(agent, max_iterations, break_condition, x)
```

#### `WhileLoopPipeline`

* Without pipeline:
* Without pipeline:

```python
while condition(x):
x = agent(x)
```

* Using pipeline:
* Using pipeline:

```python
from agentscope.pipelines import WhileLoopPipeline
Expand All @@ -201,16 +201,18 @@ This section illustrates how pipelines can simplify the implementation of logic
x = pipe(x)
```

- Using functional pipeline:
* Using functional pipeline:

```python
from agentscope.functional import whilelooppipeline

x = whilelooppipeline(x, agent, condition)
x = whilelooppipeline(agent, condition, x)
```

### Pipeline Combination

It's worth noting that AgentScope supports the combination of pipelines to create complex interactions. For example, we can create a pipeline that executes a sequence of agents in order, and then executes another pipeline that executes a sequence of agents in condition.

```python
from agentscope.pipelines import SequentialPipeline, ParallelPipeline
# Create a pipeline that executes agents in order
Expand All @@ -223,7 +225,6 @@ pipe3 = SequentialPipeline([pipe1, pipe2])
x = pipe3(x)
```


## MsgHub

`MsgHub` is designed to manage dialogue among a group of agents, allowing for the sharing of messages. Through `MsgHub`, agents can broadcast messages to all other agents in the group with `broadcast`.
Expand All @@ -241,11 +242,11 @@ class MsgHubManager:
agent.observe(msg)

def add(self, new_participant: Union[Sequence[AgentBase], AgentBase]) -> None:
"""Add new participant into this hub"""
"""Add new participant into this hub"""
# ... [code omitted for brevity]

def delete(self, participant: Union[Sequence[AgentBase], AgentBase]) -> None:
"""Delete agents from participant."""
"""Delete agents from participant."""
# ... [code omitted for brevity]
```

Expand Down Expand Up @@ -295,6 +296,4 @@ hub.add(new_agent)
hub.delete(existing_agent)
```



[[Return to the top]](#agent-interactions-dive-deeper-into-pipelines-and-message-hub)
[[Return to the top]](#agent-interactions-dive-deeper-into-pipelines-and-message-hub)
1 change: 1 addition & 0 deletions src/agentscope/pipelines/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Mapping
from ..agents.operator import Operator

# A single Operator or a Sequence of Operators
Operators = Union[Operator, Sequence[Operator]]


Expand Down

0 comments on commit 35e8a4c

Please sign in to comment.