Action parsers
sweagent.tools.parsing
Our parsers parse output from the LM into thoughts and actions.
For example, our most basic parser is the ThoughtActionParser
.
It expects the model response to be a discussion followed by a command wrapped in backticks like so:
Let's look at the files in the current directory.
Action:
```
ls -l
```
To use a specific parser, set the parse_function
key in your tool config to the type
field of the parser.
tools:
...
parse_function: "thought_action"
ParseFunction
module-attribute
ParseFunction = ActionParser | ThoughtActionParser | ActionOnlyParser | XMLThoughtActionParser | FunctionCallingParser | EditFormat | Identity | JsonParser
AbstractParseFunction
Bases: ABC
Abstract class for parsing functions. We use get to generate the right parser based on the name of the parser.
error_message
instance-attribute
error_message: str
format_error_template
property
format_error_template
ActionOnlyParser
pydantic-model
Bases: AbstractParseFunction
, BaseModel
Expects the model response to be a single command.
Fields:
-
error_message
(str
) -
type
(Literal['action_only']
)
error_message
pydantic-field
error_message: str = 'No message found in model response.'
type
pydantic-field
type: Literal['action_only'] = 'action_only'
Type for (de)serialization. Do not change.
ActionParser
pydantic-model
Bases: AbstractParseFunction
, BaseModel
Expects the model response to be a single command. Example: "ls -l"
Fields:
-
error_message
(str
) -
type
(Literal['action']
)
error_message
pydantic-field
error_message: str = ' The command you provided was not recognized. Please specify one of the commands (+ any necessary arguments) from the following list in your response. Do not include any other text.\n\n COMMANDS:\n {command_docs}\n '
type
pydantic-field
type: Literal['action'] = 'action'
Type for (de)serialization. Do not change.
EditFormat
pydantic-model
Bases: ThoughtActionParser
, BaseModel
Expects the model response to be a discussion followed by a command wrapped in backticks. Example: We'll replace the contents of the current window with the following:
import os
os.listdir()
Fields:
-
error_message
(str
) -
type
(Literal['edit_format']
)
error_message
pydantic-field
error_message: str
type
pydantic-field
type: Literal['edit_format'] = 'edit_format'
Type for (de)serialization. Do not change.
FunctionCallingParser
pydantic-model
Bases: AbstractParseFunction
, BaseModel
Expects the model response to be a LiteLLM tool call.
Fields:
-
error_message
(str
) -
type
(Literal['function_calling']
)
error_message
pydantic-field
error_message: str
type
pydantic-field
type: Literal['function_calling'] = 'function_calling'
Type for (de)serialization. Do not change.
Identity
pydantic-model
Bases: AbstractParseFunction
, BaseModel
This parser does not do any parsing. It just returns the model response as both the thought and action.
Fields:
-
error_message
(str
) -
type
(Literal['identity']
)
error_message
pydantic-field
error_message: str = ' It seems like something went wrong with your output. Please try again.\n '
type
pydantic-field
type: Literal['identity'] = 'identity'
Type for (de)serialization. Do not change.
JsonParser
pydantic-model
Bases: AbstractParseFunction
, BaseModel
Expects the model response to be a JSON object.
Fields:
-
error_message
(str
) -
type
(Literal['json']
)
error_message
pydantic-field
error_message: str
type
pydantic-field
type: Literal['json'] = 'json'
Type for (de)serialization. Do not change.
ThoughtActionParser
pydantic-model
Bases: AbstractParseFunction
, BaseModel
Expects the model response to be a discussion followed by a command wrapped in backticks. Example: Let's look at the files in the current directory.
ls -l
Fields:
-
error_message
(str
) -
type
(Literal['thought_action']
)
error_message
pydantic-field
error_message: str
type
pydantic-field
type: Literal['thought_action'] = 'thought_action'
Type for (de)serialization. Do not change.
XMLThoughtActionParser
pydantic-model
Bases: AbstractParseFunction
, BaseModel
Expects the model response to be a discussion followed by a command wrapped in XML tags.
Example:
Let's look at the files in the current directory.
Fields:
-
error_message
(str
) -
type
(Literal['xml_thought_action']
)
error_message
pydantic-field
error_message: str
type
pydantic-field
type: Literal['xml_thought_action'] = 'xml_thought_action'
Type for (de)serialization. Do not change.