Skip to content

Commit

Permalink
deploy: 8771ba9
Browse files Browse the repository at this point in the history
  • Loading branch information
DavdGao committed Jul 23, 2024
1 parent 1f3247e commit 522f698
Show file tree
Hide file tree
Showing 54 changed files with 1,867 additions and 256 deletions.
Binary file modified en/.doctrees/agentscope.agents.doctree
Binary file not shown.
Binary file modified en/.doctrees/agentscope.agents.react_agent.doctree
Binary file not shown.
Binary file modified en/.doctrees/agentscope.parsers.doctree
Binary file not shown.
Binary file not shown.
Binary file modified en/.doctrees/environment.pickle
Binary file not shown.
Binary file modified en/.doctrees/index.doctree
Binary file not shown.
Binary file modified en/.doctrees/tutorial/203-parser.doctree
Binary file not shown.
121 changes: 52 additions & 69 deletions en/_modules/agentscope/agents/react_agent.html

Large diffs are not rendered by default.

325 changes: 325 additions & 0 deletions en/_modules/agentscope/parsers/regex_tagged_content_parser.html

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions en/_modules/agentscope/service/service_toolkit.html
Original file line number Diff line number Diff line change
Expand Up @@ -504,17 +504,9 @@ <h1>Source code for agentscope.service.service_toolkit</h1><div class="highlight

execute_results = []
for i, cmd in enumerate(cmds):
func_name = cmd[&quot;name&quot;]
service_func = self.service_funcs[cmd[&quot;name&quot;]]
kwargs = cmd.get(&quot;arguments&quot;, {})

print(f&quot;&gt;&gt;&gt; Executing function {func_name} with arguments:&quot;)
for key, value in kwargs.items():
value = (
value if len(str(value)) &lt; 50 else str(value)[:50] + &quot;...&quot;
)
print(f&quot;&gt;&gt;&gt; \t{key}: {value}&quot;)

# Execute the function
try:
func_res = service_func.processed_func(**kwargs)
Expand All @@ -524,8 +516,6 @@ <h1>Source code for agentscope.service.service_toolkit</h1><div class="highlight
content=str(e),
)

print(&quot;&gt;&gt;&gt; END &quot;)

status = (
&quot;SUCCESS&quot;
if func_res.status == ServiceExecStatus.SUCCESS
Expand Down
1 change: 1 addition & 0 deletions en/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ <h1>All modules for which code is available</h1>
<li><a href="agentscope/parsers/code_block_parser.html">agentscope.parsers.code_block_parser</a></li>
<li><a href="agentscope/parsers/json_object_parser.html">agentscope.parsers.json_object_parser</a></li>
<li><a href="agentscope/parsers/parser_base.html">agentscope.parsers.parser_base</a></li>
<li><a href="agentscope/parsers/regex_tagged_content_parser.html">agentscope.parsers.regex_tagged_content_parser</a></li>
<li><a href="agentscope/parsers/tagged_content_parser.html">agentscope.parsers.tagged_content_parser</a></li>
<li><a href="agentscope/pipelines/functional.html">agentscope.pipelines.functional</a></li>
<li><a href="agentscope/pipelines/pipeline.html">agentscope.pipelines.pipeline</a></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
agentscope.parsers.regex\_tagged\_content\_parser module
========================================================

.. automodule:: agentscope.parsers.regex_tagged_content_parser
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions en/_sources/agentscope.parsers.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Submodules
agentscope.parsers.code_block_parser
agentscope.parsers.json_object_parser
agentscope.parsers.parser_base
agentscope.parsers.regex_tagged_content_parser
agentscope.parsers.tagged_content_parser

Module contents
Expand Down
48 changes: 36 additions & 12 deletions en/_sources/tutorial/203-parser.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ You should generate python code in a fenced code block as follows

AgentScope provides multiple built-in parsers, and developers can choose according to their needs.

| Target Format | Parser Class | Description |
| --- | --- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| String | `MarkdownCodeBlockParser` | Requires LLM to generate specified text within a Markdown code block marked by ```. The result is a string. |
| Dictionary | `MarkdownJsonDictParser` | Requires LLM to produce a specified dictionary within the code block marked by \```json and \```. The result is a Python dictionary. |
| | `MultiTaggedContentParser` | Requires LLM to generate specified content within multiple tags. Contents from different tags will be parsed into a single Python dictionary with different key-value pairs. |
| Target Format | Parser Class | Description |
|---------------------------|----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| String | `MarkdownCodeBlockParser` | Requires LLM to generate specified text within a Markdown code block marked by ```. The result is a string. |
| Dictionary | `MarkdownJsonDictParser` | Requires LLM to produce a specified dictionary within the code block marked by \```json and \```. The result is a Python dictionary. |
| | `MultiTaggedContentParser` | Requires LLM to generate specified content within multiple tags. Contents from different tags will be parsed into a single Python dictionary with different key-value pairs. |
| | `RegexTaggedContentParser` | For uncertain tag names and quantities, allows users to modify regular expressions, and the return result is a dictionary. |
| JSON / Python Object Type | `MarkdownJsonObjectParser` | Requires LLM to produce specified content within the code block marked by \```json and \```. The result will be converted into a Python object via json.loads. |


> **NOTE**: Compared to `MarkdownJsonDictParser`, `MultiTaggedContentParser` is more suitable for weak LLMs and when the required format is too complex.
> For example, when LLM is required to generate Python code, if the code is returned directly within a dictionary, LLM needs to be aware of escaping characters (\t, \n, ...), and the differences between double and single quotes when calling `json.loads`
>
Expand Down Expand Up @@ -263,12 +265,34 @@ In AgentScope, we achieve post-processing by calling the `to_content`, `to_memor
> None
> ```

#### Parsers

Next we will introduce two parsers for dictionary type.
For dictionary type return values, AgentScope provides multiple parsers for developers to choose from according to their needs.

#### MarkdownJsonDictParser
##### RegexTaggedContentParser

##### Initialization & Format Instruction Template
###### Initialization

`RegexTaggedContentParser` is designed for scenarios where 1) the tag name is uncertain, and 2) the number of tags is uncertain.
In this case, the parser cannot provide a general response format instruction, so developers need to provide the corresponding response format instruction (`format_instruction`) when initializing.
Of course, the developers can handle the prompt engineering by themselves optionally.

```python
from agentscope.parsers import RegexTaggedContentParser

parser = RegexTaggedContentParser(
format_instruction="""Respond with specific tags as outlined below
<thought>what you thought</thought>
<speak>what you speak</speak>
""",
try_parse_json=True, # Try to parse the content of the tag as JSON object
required_keys=["thought", "speak"] # Required keys in the returned dictionary
)
```

##### MarkdownJsonDictParser

###### Initialization & Format Instruction Template

- `MarkdownJsonDictParser` requires LLM to generate dictionary within a code block fenced by \```json and \``` tags.

Expand Down Expand Up @@ -303,7 +327,7 @@ This parameter can be a string or a dictionary. For dictionary, it will be autom
```
````

##### Validation
###### Validation

The `content_hint` parameter in `MarkdownJsonDictParser` also supports type validation based on Pydantic. When initializing, you can set `content_hint` to a Pydantic model class, and AgentScope will modify the `instruction_format` attribute based on this class. Besides, Pydantic will be used to validate the dictionary returned by LLM during parsing.

Expand Down Expand Up @@ -346,11 +370,11 @@ parser.parser("""
""")
````

#### MultiTaggedContentParser
##### MultiTaggedContentParser

`MultiTaggedContentParser` asks LLM to generate specific content within multiple tag pairs. The content from different tag pairs will be parsed into a single Python dictionary. Its usage is similar to `MarkdownJsonDictParser`, but the initialization method is different, and it is more suitable for weak LLMs or complex return content.

##### Initialization & Format Instruction Template
###### Initialization & Format Instruction Template

Within `MultiTaggedContentParser`, each tag pair will be specified by as `TaggedContent` object, which contains
- Tag name (`name`), the key value in the returned dictionary
Expand Down Expand Up @@ -393,7 +417,7 @@ Respond with specific tags as outlined below, and the content between [FINISH_DI
[FINISH_DISCUSSION]true/false, whether the discussion is finished[/FINISH_DISCUSSION]
```

##### Parse Function
###### Parse Function

- `MultiTaggedContentParser`'s parsing result is a dictionary, whose keys are the value of `name` in the `TaggedContent` objects.
The following is an example of parsing the LLM response in the werewolf game:
Expand Down
2 changes: 1 addition & 1 deletion en/agentscope.agents.html
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Link to this headi
their own needs.</p>
<dl class="py method">
<dt class="sig sig-object py" id="agentscope.agents.ReActAgent.__init__">
<span class="sig-name descname"><span class="pre">__init__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">model_config_name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">service_toolkit</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="agentscope.service.service_toolkit.html#agentscope.service.service_toolkit.ServiceToolkit" title="agentscope.service.service_toolkit.ServiceToolkit"><span class="pre">ServiceToolkit</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sys_prompt</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">&quot;You're</span> <span class="pre">a</span> <span class="pre">helpful</span> <span class="pre">assistant.</span> <span class="pre">Your</span> <span class="pre">name</span> <span class="pre">is</span> <span class="pre">{name}.&quot;</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_iters</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">bool</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Any</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="_modules/agentscope/agents/react_agent.html#ReActAgent.__init__"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#agentscope.agents.ReActAgent.__init__" title="Link to this definition"></a></dt>
<span class="sig-name descname"><span class="pre">__init__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">model_config_name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">service_toolkit</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="agentscope.service.service_toolkit.html#agentscope.service.service_toolkit.ServiceToolkit" title="agentscope.service.service_toolkit.ServiceToolkit"><span class="pre">ServiceToolkit</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">sys_prompt</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">&quot;You're</span> <span class="pre">a</span> <span class="pre">helpful</span> <span class="pre">assistant.</span> <span class="pre">Your</span> <span class="pre">name</span> <span class="pre">is</span> <span class="pre">{name}.&quot;</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_iters</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">bool</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="_modules/agentscope/agents/react_agent.html#ReActAgent.__init__"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#agentscope.agents.ReActAgent.__init__" title="Link to this definition"></a></dt>
<dd><p>Initialize the ReAct agent with the given name, model config name
and tools.</p>
<dl class="field-list simple">
Expand Down
Loading

0 comments on commit 522f698

Please sign in to comment.