agentscope.parsers.parser_base module

The base class for model response parser.

class agentscope.parsers.parser_base.ParserBase[源代码]

基类:ABC

The base class for model response parser.

abstract parse(response: ModelResponse) ModelResponse[源代码]

Parse the response text to a specific object, and stored in the parsed field of the response object.

class agentscope.parsers.parser_base.DictFilterMixin(keys_to_memory: str | bool | Sequence[str], keys_to_content: str | bool | Sequence[str], keys_to_metadata: str | bool | Sequence[str])[源代码]

基类:object

A mixin class to filter the parsed response by keys. It allows users to set keys to be filtered during speaking, storing in memory, and returning in the agent reply function.

__init__(keys_to_memory: str | bool | Sequence[str], keys_to_content: str | bool | Sequence[str], keys_to_metadata: str | bool | Sequence[str]) None[源代码]

Initialize the mixin class with the keys to be filtered during speaking, storing in memory, and returning in the agent reply function.

参数:
  • keys_to_memory (Optional[Union[str, bool, Sequence[str]]]) – The key or keys to be filtered in to_memory method. If it’s - False, None will be returned in the to_memory method - str, the corresponding value will be returned - List[str], a filtered dictionary will be returned - True, the whole dictionary will be returned

  • keys_to_content (Optional[Union[str, bool, Sequence[str]]) – The key or keys to be filtered in to_content method. If it’s - False, None will be returned in the to_content method - str, the corresponding value will be returned - List[str], a filtered dictionary will be returned - True, the whole dictionary will be returned

  • keys_to_metadata (Optional[Union[str, bool, Sequence[str]]]) – The key or keys to be filtered in to_metadata method. If it’s - False, None will be returned in the to_metadata method - str, the corresponding value will be returned - List[str], a filtered dictionary will be returned - True, the whole dictionary will be returned

to_memory(parsed_response: dict, allow_missing: bool = False) str | dict | None[源代码]

Filter the fields that will be stored in memory.

to_content(parsed_response: dict, allow_missing: bool = False) str | dict | None[源代码]

Filter the fields that will be fed into the content field in the returned message, which will be exposed to other agents.

to_metadata(parsed_response: dict, allow_missing: bool = False) str | dict | None[源代码]

Filter the fields that will be fed into the returned message directly to control the application workflow.