Junaidb commited on
Commit
b1b9f8f
·
verified ·
1 Parent(s): 0d486ad

Update components/agentcreation.py

Browse files
Files changed (1) hide show
  1. components/agentcreation.py +34 -50
components/agentcreation.py CHANGED
@@ -31,14 +31,39 @@ async def create_keypair(agent):
31
  raise
32
 
33
 
34
- async def transfer_sol(from_keypair, to_pubkey, amount_sol):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  """Transfer SOL from one account to another"""
36
  try:
 
37
  lamports = int(amount_sol * 1e9)
38
 
39
  transfer_ix = transfer(
40
  TransferParams(
41
- from_pubkey=from_keypair.pubkey(),
42
  to_pubkey=to_pubkey,
43
  lamports=lamports
44
  ))
@@ -60,24 +85,7 @@ async def transfer_sol(from_keypair, to_pubkey, amount_sol):
60
 
61
 
62
 
63
- def load_keypair(agent):
64
 
65
- document=coll.find_one({"owner":"system"})
66
- keypair=None
67
- agents=document.get("agents")
68
- print(agents)
69
-
70
- for doc in agents:
71
- if doc["agent_id"]==agent:
72
- keypair=doc["secret_key"]
73
-
74
- secret_key_bytes =bytes.fromhex(keypair)
75
- keypair = Keypair.from_bytes(secret_key_bytes)
76
-
77
- print(f"✅ Keypair loaded")
78
- print(f"📍 Public Key: {keypair.pubkey()}")
79
- publickey=str(keypair.pubkey())
80
- return publickey
81
 
82
 
83
 
@@ -85,7 +93,7 @@ def load_keypair(agent):
85
  class VelocityPayableAgent():
86
 
87
  def __init__(self):
88
- self.tools = [load_keypair,transfer_sol]
89
 
90
 
91
 
@@ -105,28 +113,8 @@ class VelocityPayableAgent():
105
  def Agent(self,user_input):
106
  client = Groq(api_key="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")
107
  available_functions= {
108
- "load_keypair": load_keypair,
109
  "transfer_sol":transfer_sol,
110
  }
111
- load_keypair_tool = {
112
- "type": "function",
113
- "function": {
114
- "name": "load_keypair",
115
- "description": "Load the Solana keypair for for the provided agent id.",
116
- "parameters": {
117
- "type": "object",
118
- "properties": {
119
- "agent":{
120
- "type":"string",
121
- "description":"agents id"
122
-
123
- }
124
- },
125
- "required": ["agent"]
126
- }
127
- }
128
- }
129
-
130
  transfer_sol_tool = {
131
  "type": "function",
132
  "function": {
@@ -135,9 +123,9 @@ class VelocityPayableAgent():
135
  "parameters": {
136
  "type": "object",
137
  "properties": {
138
- "from_keypair": {
139
  "type": "string",
140
- "description": "secret key of the agent"
141
  },
142
  "to_pubkey": {
143
  "type": "string",
@@ -159,10 +147,9 @@ class VelocityPayableAgent():
159
  Rules:
160
  1. You MUST call a tool for every query from the user.
161
  2. You are NOT allowed to answer directly.
162
- 3. If multiple tools exist, choose the one that is closest to the user's intent.
163
- 4. Always return a tool call in the correct function-calling JSON format.
164
- 5. When unsure, still pick a tool instead of answering directly.
165
- 6. Do not apologize, do not explain, do not output reasoning—only valid tool calls.
166
  """},
167
  {"role": "user", "content": user_input}]
168
 
@@ -191,7 +178,4 @@ class VelocityPayableAgent():
191
  print(final.choices[0].message.content)
192
  return final.choices[0].message.content
193
 
194
-
195
-
196
-
197
-
 
31
  raise
32
 
33
 
34
+
35
+
36
+ def load_keypair(agent):
37
+
38
+ document=coll.find_one({"owner":"system"})
39
+ keypair=None
40
+ agents=document.get("agents")
41
+ print(agents)
42
+
43
+ for doc in agents:
44
+ if doc["agent_id"]==agent:
45
+ keypair=doc["secret_key"]
46
+
47
+ secret_key_bytes =bytes.fromhex(keypair)
48
+ keypair = Keypair.from_bytes(secret_key_bytes)
49
+
50
+ print(f"✅ Keypair loaded")
51
+ print(f"📍 Public Key: {keypair.pubkey()}")
52
+ publickey=str(keypair.pubkey())
53
+ return publickey
54
+
55
+
56
+
57
+
58
+ async def transfer_sol(agent_id, to_pubkey, amount_sol):
59
  """Transfer SOL from one account to another"""
60
  try:
61
+ from_publickey=load_keypair(agent_id)
62
  lamports = int(amount_sol * 1e9)
63
 
64
  transfer_ix = transfer(
65
  TransferParams(
66
+ from_pubkey=from_publickey,
67
  to_pubkey=to_pubkey,
68
  lamports=lamports
69
  ))
 
85
 
86
 
87
 
 
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
 
91
 
 
93
  class VelocityPayableAgent():
94
 
95
  def __init__(self):
96
+ self.tools = [transfer_sol]
97
 
98
 
99
 
 
113
  def Agent(self,user_input):
114
  client = Groq(api_key="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")
115
  available_functions= {
 
116
  "transfer_sol":transfer_sol,
117
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  transfer_sol_tool = {
119
  "type": "function",
120
  "function": {
 
123
  "parameters": {
124
  "type": "object",
125
  "properties": {
126
+ "agent_id": {
127
  "type": "string",
128
+ "description": "id of the agent"
129
  },
130
  "to_pubkey": {
131
  "type": "string",
 
147
  Rules:
148
  1. You MUST call a tool for every query from the user.
149
  2. You are NOT allowed to answer directly.
150
+ 3. Always return tool call in the correct function-calling JSON format.
151
+ 4. When unsure, still pick a tool instead of answering directly.
152
+ 5. Do not apologize, do not explain, do not output reasoning—only valid tool calls.
 
153
  """},
154
  {"role": "user", "content": user_input}]
155
 
 
178
  print(final.choices[0].message.content)
179
  return final.choices[0].message.content
180
 
181
+