agentscope.parsers.parser_base module
The base class for model response parser.
- class agentscope.parsers.parser_base.ParserBase[source]
Bases:
ABC
The base class for model response parser.
- abstract parse(response: ModelResponse) ModelResponse [source]
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])[source]
Bases:
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 [source]
Initialize the mixin class with the keys to be filtered during speaking, storing in memory, and returning in the agent reply function.
- Parameters:
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 [source]
Filter the fields that will be stored in memory.