Skip to content

Commit

Permalink
Merge pull request #208 from polywrap/chore/agent-loop-network-aware
Browse files Browse the repository at this point in the history
chore: agent loop network aware
  • Loading branch information
dOrgJelli authored Apr 12, 2024
2 parents 3219529 + ef8687e commit 257e9ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion autotx/AutoTx.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(self, prompt: str, non_interactive: bool, silent: bool = False) -> None:

agents_information = self.get_agents_information(self.agents)

goal = build_goal(prompt, agents_information, self.manager.address, non_interactive)
goal = build_goal(prompt, agents_information, self.manager.address, self.network.chain_id.name, non_interactive)

verifier_agent = AssistantAgent(
name="verifier",
Expand Down
14 changes: 8 additions & 6 deletions autotx/utils/agent/build_goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ def __init__(self, message: str):

DefineGoalResponse = typing.Union[GoalResponse, MissingInfoResponse, InvalidPromptResponse]

def get_persona(smart_account_address: ETHAddress) -> str:
def get_persona(smart_account_address: ETHAddress, current_network: str) -> str:
return dedent(
f"""
You are an AI assistant that helps the user define goals and tasks for your agents.
You can analyze prompts and provide the user with a goal to be executed by the agents.
When dealing with Ethereum transactions, assume the following is the user's address: {smart_account_address}
When dealing with Ethereum transactions, assume the following:
- The user's address: {smart_account_address}
- The network to interact with: {current_network}
"""
)

def build_goal(prompt: str, agents_information: str, smart_account_address: ETHAddress, non_interactive: bool) -> str:
def build_goal(prompt: str, agents_information: str, smart_account_address: ETHAddress, current_network: str, non_interactive: bool) -> str:
response: DefineGoalResponse | None = None
chat_history = f"User: {prompt}"

while True:
response = analyze_user_prompt(chat_history, agents_information, smart_account_address)
response = analyze_user_prompt(chat_history, agents_information, smart_account_address, current_network)
if response.type == "missing_info":
autotx_message = f"Missing information: {response.message}"

Expand All @@ -64,7 +66,7 @@ def build_goal(prompt: str, agents_information: str, smart_account_address: ETHA
elif response.type == "goal":
return response.goal

def analyze_user_prompt(chat_history: str, agents_information: str, smart_account_address: ETHAddress) -> DefineGoalResponse:
def analyze_user_prompt(chat_history: str, agents_information: str, smart_account_address: ETHAddress, current_network: str) -> DefineGoalResponse:
template = dedent(
"""
Based on the following chat history between you and the user:
Expand Down Expand Up @@ -107,7 +109,7 @@ def analyze_user_prompt(chat_history: str, agents_information: str, smart_accoun
model=os.environ.get("OPENAI_MODEL_NAME", "gpt-4-turbo-preview"),
response_format={"type": "json_object"},
messages=[
{ "role": "system", "content": get_persona(smart_account_address) },
{ "role": "system", "content": get_persona(smart_account_address, current_network) },
{ "role": "user", "content": formatted_template }
],
)
Expand Down

0 comments on commit 257e9ef

Please sign in to comment.