Skip to content

Commit

Permalink
add info as property of agent
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-ashkinaze committed Jul 7, 2024
1 parent a259fe1 commit 91078d5
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions plurals/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Optional, Dict, Any
from plurals.helpers import *
from litellm import completion
import warnings

DEFAULTS = load_yaml("instructions.yaml")

class Agent:
Expand Down Expand Up @@ -33,6 +35,7 @@ class Agent:
original_task_description (str): The original task description without modifications.
current_task_description (str): The current task description that appends `previous_responses'.
history (list): A list of dicts like {'prompt':prompt, 'response':response, 'model':model}
info (dict): A dictionary of different attributes of the agent.
"""

def __init__(self,
Expand All @@ -48,7 +51,7 @@ def __init__(self,
**kwargs):
self.model = model
self.system_instructions = system_instructions
self.history = []
self._history = []
self.persona_mapping = persona_mapping
self.task_description = task
self.persona = persona
Expand Down Expand Up @@ -200,7 +203,7 @@ def _get_response(self, task: str) -> Optional[str]:
content = response.choices[0].message.content
prompts = {'system': next((msg['content'] for msg in messages if msg['role'] == 'system'), None),
'user': next((msg['content'] for msg in messages if msg['role'] == 'user'), None)}
self.history.append({'prompts': prompts, 'response': content, 'model': self.model})
self._history.append({'prompts': prompts, 'response': content, 'model': self.model})
return content
except Exception as e:
print(f"Error fetching response from LLM: {e}")
Expand Down Expand Up @@ -289,3 +292,26 @@ def _convert_ideology_to_query_str(self, ideology: str) -> str:
elif ideology.lower() == "very conservative":
return "ideo5 == 'Very conservative'"
return ""

@property
def history(self):
if not self._history:
warnings.warn("No history found. Please process a task first!")
return None
else:
return self._history

@ property
def info(self):
return {"task": self.task_description,
"system_instructions": self.system_instructions,
"history": self.history,
"persona": self.persona,
"ideology": self.ideology,
"query_str": self.query_str,
"model": self.model,
"persona_template": self.persona_template,
"kwargs": self.kwargs}
def __repr__(self):
return str(self.info)

0 comments on commit 91078d5

Please sign in to comment.