88import logging
99from typing import Any , Dict , List , Optional
1010
11- from solders .hash import Hash
1211from solders .keypair import Keypair
13- from solders .message import Message
1412from solders .pubkey import Pubkey as PublicKey
1513from solders .transaction import Transaction
1614
@@ -96,23 +94,17 @@ async def register_agent(
9694 )
9795
9896 try :
99- # Derive PDA for agent registry entry
100- agent_pda = self .client .derive_agent_pda ( agent_id , owner . pubkey ())
101-
102- # Create transaction
103- # TODO: Create proper transaction with instructions
104- message = Message . new_with_blockhash (
105- instructions = [], payer = owner . pubkey (), blockhash = Hash . default ()
97+ # Build register agent instruction
98+ instruction = self .client .build_register_agent_instruction (
99+ agent_id = agent_id ,
100+ name = name ,
101+ description = description ,
102+ owner = owner . pubkey (),
103+ metadata_uri = metadata_uri ,
106104 )
107- transaction = Transaction .new_unsigned (message )
108105
109- # TODO: Add proper instruction for agent registration
110- # This would use the actual program instruction from IDL
111- # For now, we'll simulate the structure
112- logger .info (
113- f"Registering agent { agent_id } at PDA { agent_pda } "
114- f"for owner { owner .pubkey ()} "
115- )
106+ # Create transaction
107+ transaction = Transaction .new_with_payer ([instruction ], owner .pubkey ())
116108
117109 # Send transaction
118110 signature = await self .client .send_transaction (transaction , [owner ])
@@ -160,21 +152,17 @@ async def update_agent(
160152 validate_url (updates ["metadata_uri" ], "metadata_uri" )
161153
162154 try :
163- # Derive PDA for agent registry entry
164- agent_pda = self .client .derive_agent_pda ( agent_id , owner . pubkey ())
165-
166- # Create transaction
167- # TODO: Create proper transaction with instructions
168- message = Message . new_with_blockhash (
169- instructions = [], payer = owner . pubkey (), blockhash = Hash . default ()
155+ # Build update agent instruction
156+ instruction = self .client .build_update_agent_instruction (
157+ agent_id = agent_id ,
158+ owner = owner . pubkey (),
159+ name = updates . get ( "name" ),
160+ description = updates . get ( "description" ),
161+ status = updates . get ( "status" ),
170162 )
171- transaction = Transaction .new_unsigned (message )
172163
173- # TODO: Add proper instruction for agent update
174- logger .info (
175- f"Updating agent { agent_id } at PDA { agent_pda } "
176- f"with updates: { list (updates .keys ())} "
177- )
164+ # Create transaction
165+ transaction = Transaction .new_with_payer ([instruction ], owner .pubkey ())
178166
179167 # Send transaction
180168 signature = await self .client .send_transaction (transaction , [owner ])
@@ -208,19 +196,35 @@ async def get_agent(
208196 if account_data is None :
209197 return None
210198
211- # TODO: Deserialize account data to AgentRegistryEntry
212- # This would use the IDL to properly deserialize the account
213- # For now, return a mock entry
214- return AgentRegistryEntry (
215- agent_id = agent_id ,
216- name = f"Agent { agent_id } " ,
217- description = "Mock agent entry" ,
218- agent_version = "1.0.0" ,
219- owner = str (owner ),
220- status = AgentStatus .ACTIVE ,
221- service_endpoints = [],
222- skills = [],
223- )
199+ # Deserialize account data using the client's deserialization method
200+ if "data" in account_data and isinstance (
201+ account_data ["data" ], (list , bytes )
202+ ):
203+ if isinstance (account_data ["data" ], list ):
204+ # Convert list to bytes if needed
205+ account_bytes = bytes (account_data ["data" ])
206+ else :
207+ account_bytes = account_data ["data" ]
208+
209+ deserialized_data = await self .client .deserialize_agent_account (
210+ account_bytes
211+ )
212+
213+ return AgentRegistryEntry (
214+ agent_id = deserialized_data ["agent_id" ],
215+ name = deserialized_data ["name" ],
216+ description = deserialized_data ["description" ],
217+ agent_version = "1.0.0" , # Default version
218+ owner = deserialized_data ["owner" ],
219+ status = AgentStatus (deserialized_data ["status" ]),
220+ service_endpoints = [], # Placeholder
221+ skills = [], # Placeholder
222+ extended_metadata_uri = deserialized_data .get ("metadata_uri" ),
223+ created_at = deserialized_data .get ("created_at" , 0 ),
224+ updated_at = deserialized_data .get ("updated_at" , 0 ),
225+ )
226+ else :
227+ return None
224228
225229 except Exception as e :
226230 logger .error (f"Failed to retrieve agent { agent_id } : { e } " )
@@ -246,18 +250,13 @@ async def deregister_agent(self, agent_id: str, owner: Keypair) -> str:
246250 raise AgentNotFoundError (f"Agent with ID '{ agent_id } ' not found for owner" )
247251
248252 try :
249- # Derive PDA for agent registry entry
250- agent_pda = self .client .derive_agent_pda (agent_id , owner .pubkey ())
251-
252- # Create transaction
253- # TODO: Create proper transaction with instructions
254- message = Message .new_with_blockhash (
255- instructions = [], payer = owner .pubkey (), blockhash = Hash .default ()
253+ # Build deregister agent instruction
254+ instruction = self .client .build_deregister_agent_instruction (
255+ agent_id = agent_id , owner = owner .pubkey ()
256256 )
257- transaction = Transaction .new_unsigned (message )
258257
259- # TODO: Add proper instruction for agent deregistration
260- logger . info ( f"Deregistering agent { agent_id } at PDA { agent_pda } " )
258+ # Create transaction
259+ transaction = Transaction . new_with_payer ([ instruction ], owner . pubkey () )
261260
262261 # Send transaction
263262 signature = await self .client .send_transaction (transaction , [owner ])
0 commit comments