ucg_v1 / app_layer_agent.py
Junaidb's picture
Update app_layer_agent.py
6e61cbe verified
import json
from engine import UCGEngine,TOOLS
from groq import Groq
from components.ucg_g1 import UGC_GRAPH_1
client = Groq(api_key="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")
ucg_engine=UCGEngine(UGC_GRAPH_1,TOOLS)
#available_functions = {
# "UCGEngine":runner.run
#}
system='''
You are an assistant for the UGCEngine. Your task is:
- Take the user query , infer the Operation from Supported Operations along with their respective parameters
- Output exactly one JSON object with:
{{
"operation": "<Infered UGC operation name>",
"state": {{
... all required fields for the operation ...
}}
}}
- Do not add explanations , information or extra text.
- Only include required fields. Do not hallucinate.
Supported Operations:
NetworkResolver
Inputs:
- address (string)
InfuraRPC (eth address balances)
Inputs:
- address (string)
HeliusAPI (solana address balances)
Inputs:
address (string)
EthereumSigner
Inputs:
- address (string)
- payload (hex string)
SolanaSigner
Inputs:
- address (string)
- payload (hex string)
SolanaPayment
Inputs:
- address (string)
- to (string)
- amount (string)
Note: address not starting with 0x is solana address
'''
class UCGBRIDGE():
def __init__(self):
"""
ucg_engine: your existing UCGEngine instance
"""
self.engine=ucg_engine
def run_conversation(self,user_prompt):
"""Run a conversation with tool calling"""
messages = [
{
"role":"system",
"content":system
},
{
"role": "user",
"content": user_prompt,
}
]
#Step 1: Make initial API call
response = client.chat.completions.create(
model="moonshotai/kimi-k2-instruct-0905",
messages=messages,
)
response_message = response.choices[0].message.content
json_=json.loads(response_message)
print(response_message)
result =self.engine.run(json_["operation"],json_["state"])
return result