Eric Botti commited on
Commit
672c019
·
1 Parent(s): f930bca

human validation retry

Browse files
Files changed (1) hide show
  1. src/agent_interfaces.py +11 -6
src/agent_interfaces.py CHANGED
@@ -122,8 +122,6 @@ class BaseAgentInterface:
122
 
123
  return output
124
 
125
- # How agents actually generate responses
126
-
127
  def _generate(self) -> str:
128
  """Generates a response from the Agent."""
129
  # This is the BaseAgent class, and thus has no response logic
@@ -168,10 +166,17 @@ class HumanAgentInterface(BaseAgentInterface):
168
 
169
  if response:
170
  # only works because current outputs have only 1 field...
171
- fields = {output_format.model_fields.copy().popitem()[0]: response.content}
172
- if additional_fields:
173
- fields.update(additional_fields)
174
- output = output_format.model_validate(fields)
 
 
 
 
 
 
 
175
  else:
176
  output = None
177
 
 
122
 
123
  return output
124
 
 
 
125
  def _generate(self) -> str:
126
  """Generates a response from the Agent."""
127
  # This is the BaseAgent class, and thus has no response logic
 
166
 
167
  if response:
168
  # only works because current outputs have only 1 field...
169
+ try:
170
+ fields = {output_format.model_fields.copy().popitem()[0]: response.content}
171
+ if additional_fields:
172
+ fields.update(additional_fields)
173
+ output = output_format.model_validate(fields)
174
+
175
+ except ValidationError as e:
176
+ retry_message = Message(type="retry", content=f"Error formatting response: {e} \n\n Please try again.")
177
+ self.add_message(retry_message)
178
+ output = None
179
+
180
  else:
181
  output = None
182