Spaces:
Sleeping
Sleeping
Update app_layer_agent.py
Browse files- app_layer_agent.py +67 -61
app_layer_agent.py
CHANGED
|
@@ -11,35 +11,61 @@ runner=UCGEngine(UGC_GRAPH_1,TOOLS)
|
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
-
def UCGExecutor(operation: str,address: str, ):
|
| 15 |
-
"""
|
| 16 |
-
Execute a UGC graph operation for a given address.
|
| 17 |
-
|
| 18 |
-
Args:
|
| 19 |
-
|
| 20 |
-
operation (str): The UGC operation to run (goal node in the graph).
|
| 21 |
-
address (str): Ethereum or Solana wallet address.
|
| 22 |
-
|
| 23 |
-
Returns:
|
| 24 |
-
dict: The final state returned by the UGC engine.
|
| 25 |
-
"""
|
| 26 |
-
inputs = {"address": address}
|
| 27 |
-
|
| 28 |
-
# Assuming `runner` is an instance of UGCRunner with UGC_GRAPH_1 and TOOLS
|
| 29 |
-
result = runner.run(operation,inputs)
|
| 30 |
-
return result
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
available_functions = {
|
| 36 |
-
"
|
| 37 |
|
| 38 |
}
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def run_conversation(user_prompt):
|
| 44 |
"""Run a conversation with tool calling"""
|
| 45 |
|
|
@@ -47,25 +73,7 @@ def run_conversation(user_prompt):
|
|
| 47 |
|
| 48 |
{
|
| 49 |
"role":"system",
|
| 50 |
-
"content":
|
| 51 |
-
|
| 52 |
-
You are an AI assistant for the UGC Engine. Your job is to convert a user's natural language query into a valid tool call for the UGCExecutor.
|
| 53 |
-
|
| 54 |
-
The tool accepts only two fields:
|
| 55 |
-
1. "address": The wallet address (Ethereum hex or Solana Base58) to operate on.
|
| 56 |
-
2. "operation": The UGC operation/tool to run.
|
| 57 |
-
|
| 58 |
-
Valid operations/tools available:
|
| 59 |
-
- InfuraRPC: Fetch ETH balance for an Ethereum address.
|
| 60 |
-
- HeliusAPI: Fetch SOL balance for a Solana address.
|
| 61 |
-
- EthereumSigner: Produce a cryptographic signature for a given Ethereum address.
|
| 62 |
-
- SolanaSigner: Produce a cryptographic signature for a given Solana address.
|
| 63 |
-
|
| 64 |
-
Analyze the user query to determine:
|
| 65 |
-
- Which wallet address is mentioned.
|
| 66 |
-
- Which operation/tool the query implies.
|
| 67 |
-
Then call the tool with the required inputs
|
| 68 |
-
'''
|
| 69 |
},
|
| 70 |
{
|
| 71 |
"role": "user",
|
|
@@ -75,33 +83,31 @@ Then call the tool with the required inputs
|
|
| 75 |
|
| 76 |
# Define the tool schema
|
| 77 |
tools = [
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
"description": "The wallet address to operate on (Ethereum hex or Solana Base58)."
|
| 95 |
-
},
|
| 96 |
-
|
| 97 |
-
},
|
| 98 |
-
"required": ["address", "operation"],
|
| 99 |
-
"additionalProperties": False
|
| 100 |
}
|
|
|
|
|
|
|
|
|
|
| 101 |
}
|
|
|
|
| 102 |
}
|
| 103 |
|
| 104 |
-
|
| 105 |
]
|
| 106 |
|
| 107 |
# Step 1: Make initial API call
|
|
@@ -128,7 +134,7 @@ Then call the tool with the required inputs
|
|
| 128 |
function_args = json.loads(tool_call.function.arguments)
|
| 129 |
function_response = function_to_call(
|
| 130 |
operation=function_args.get("operation"),
|
| 131 |
-
address=function_args.get("
|
| 132 |
)
|
| 133 |
|
| 134 |
# Add tool response to conversation
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
available_functions = {
|
| 19 |
+
"UCGEngine":runner.run
|
| 20 |
|
| 21 |
}
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
+
system='''
|
| 27 |
+
You are an autonomous agent with access to the UGC_Execution_Tool.
|
| 28 |
+
|
| 29 |
+
The tool has 2 parameters :
|
| 30 |
+
Operation : The operation to perform from Supported Operations inferred from the user request
|
| 31 |
+
State: The required parameters for that operation inferred from the user request
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Supported Operations:
|
| 36 |
+
|
| 37 |
+
1. NetworkResolver
|
| 38 |
+
Inputs:
|
| 39 |
+
- address (string)
|
| 40 |
+
|
| 41 |
+
2. InfuraRPC
|
| 42 |
+
Inputs:
|
| 43 |
+
- address (string)
|
| 44 |
+
|
| 45 |
+
3. HeliusAPI
|
| 46 |
+
Inputs:
|
| 47 |
+
- address (string)
|
| 48 |
+
|
| 49 |
+
4. EthereumSigner
|
| 50 |
+
Inputs:
|
| 51 |
+
- address (string)
|
| 52 |
+
- payload (hex string)
|
| 53 |
+
|
| 54 |
+
5. SolanaSigner
|
| 55 |
+
Inputs:
|
| 56 |
+
- address (string)
|
| 57 |
+
- payload (hex string)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
7. SolanaPayment
|
| 61 |
+
Inputs:
|
| 62 |
+
- address (string)
|
| 63 |
+
- to (string)
|
| 64 |
+
- amount (string)
|
| 65 |
+
|
| 66 |
+
'''
|
| 67 |
+
|
| 68 |
+
|
| 69 |
def run_conversation(user_prompt):
|
| 70 |
"""Run a conversation with tool calling"""
|
| 71 |
|
|
|
|
| 73 |
|
| 74 |
{
|
| 75 |
"role":"system",
|
| 76 |
+
"content":system
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
},
|
| 78 |
{
|
| 79 |
"role": "user",
|
|
|
|
| 83 |
|
| 84 |
# Define the tool schema
|
| 85 |
tools = [
|
| 86 |
+
|
| 87 |
+
{
|
| 88 |
+
"type": "function",
|
| 89 |
+
"function": {
|
| 90 |
+
"name": "UGC_Execution_Tool",
|
| 91 |
+
"description": "Execute a specified operation with the provided state using the UGCEngine",
|
| 92 |
+
"parameters":
|
| 93 |
+
"type": "object",
|
| 94 |
+
"properties": {
|
| 95 |
+
"operation": {
|
| 96 |
+
"type": "string",
|
| 97 |
+
"description": "The name of the operation to execute. Must correspond to a valid operation in Supported Operations."
|
| 98 |
+
},
|
| 99 |
+
"state": {
|
| 100 |
+
"type": "object",
|
| 101 |
+
"description": "Dictionary of input values for the operation inferred from the user query for the Supported Operations",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
}
|
| 103 |
+
},
|
| 104 |
+
"required": ["operation", "state"],
|
| 105 |
+
"additionalProperties": false
|
| 106 |
}
|
| 107 |
+
}
|
| 108 |
}
|
| 109 |
|
| 110 |
+
|
| 111 |
]
|
| 112 |
|
| 113 |
# Step 1: Make initial API call
|
|
|
|
| 134 |
function_args = json.loads(tool_call.function.arguments)
|
| 135 |
function_response = function_to_call(
|
| 136 |
operation=function_args.get("operation"),
|
| 137 |
+
address=function_args.get("state")
|
| 138 |
)
|
| 139 |
|
| 140 |
# Add tool response to conversation
|