11import os
2- import httpx
3- import logging
42
5- from langchain_openai import ChatOpenAI
3+ import opengradient as og
64from langgraph .prebuilt import create_react_agent
7- from langchain_google_genai import ChatGoogleGenerativeAI
85from langchain_core .language_models .chat_models import BaseChatModel
96
107from agent .tools import create_investor_agent_toolkit , create_analytics_agent_toolkit
118from onchain .tokens .metadata import TokenMetadataRepo
129from server import config
13- from web3 import Web3
14-
15- from x402v2 import x402Client as x402Clientv2
16- from x402v2 .http .clients import x402HttpxClient as x402HttpxClientv2
17- from x402v2 .mechanisms .evm import EthAccountSigner as EthAccountSignerv2
18- from x402v2 .mechanisms .evm .exact .register import (
19- register_exact_evm_client as register_exact_evm_clientv2 ,
20- )
21- from x402v2 .mechanisms .evm .upto .register import (
22- register_upto_evm_client as register_upto_evm_clientv2 ,
23- )
24-
25- logging .getLogger ("x402.httpx" ).setLevel (logging .DEBUG )
26-
27- WEB3_CONFIG = Web3 (Web3 .HTTPProvider (config .OG_RPC_URL ))
28- WALLET_ACCOUNT = WEB3_CONFIG .eth .account .from_key (config .WALLET_PRIV_KEY )
29- BASE_TESTNET_NETWORK = "eip155:84532"
30-
31- x402_client = x402Clientv2 ()
32- register_exact_evm_clientv2 (
33- x402_client ,
34- EthAccountSignerv2 (WALLET_ACCOUNT ),
35- networks = [BASE_TESTNET_NETWORK ],
36- )
37- register_upto_evm_clientv2 (
38- x402_client ,
39- EthAccountSignerv2 (WALLET_ACCOUNT ),
40- networks = [BASE_TESTNET_NETWORK ],
41- )
42-
43-
44- TIMEOUT = httpx .Timeout (
45- timeout = 90.0 ,
46- connect = 15.0 ,
47- read = 15.0 ,
48- write = 30.0 ,
49- pool = 10.0 ,
50- )
51-
52- LIMITS = httpx .Limits (
53- max_keepalive_connections = 100 ,
54- max_connections = 500 ,
55- keepalive_expiry = 60 * 20 , # 20 minutes
56- )
5710
5811
5912##
6013# OpenRouter LLM Configuration
6114##
6215
63- GOOGLE_GEMINI_25_PRO_MODEL = "gemini-2.5-pro"
64- GOOGLE_GEMINI_25_FLASH_MODEL = "gemini-2.5-flash"
65- GROK_MODEL = "x-ai/grok-2-1212" # $2/M input tokens; $10/M output tokens
66-
67- x402_http_client = x402HttpxClientv2 (
68- x402_client ,
69- timeout = TIMEOUT ,
70- limits = LIMITS ,
71- http2 = False ,
72- follow_redirects = False ,
73- verify = False ,
74- )
75-
7616# Select model based on configuration
77- SUGGESTIONS_MODEL = GOOGLE_GEMINI_25_FLASH_MODEL
78- REASONING_MODEL = GOOGLE_GEMINI_25_PRO_MODEL
17+ SUGGESTIONS_MODEL = og .TEE_LLM .GEMINI_2_5_FLASH
18+ REASONING_MODEL = og .TEE_LLM .GEMINI_2_5_PRO
19+
20+ opengradient_client = og .LLM (
21+ private_key = config .WALLET_PRIV_KEY ,
22+ rpc_url = config .OG_RPC_URL ,
23+ )
7924
8025
8126def create_suggestions_model () -> BaseChatModel :
82- return ChatOpenAI (
83- model = SUGGESTIONS_MODEL ,
27+ return og .agents .langchain_adapter (
28+ client = opengradient_client ,
29+ model_cid = SUGGESTIONS_MODEL ,
8430 temperature = 0.3 ,
8531 max_tokens = 1000 ,
86- api_key = config .DUMMY_X402_API_KEY ,
87- http_async_client = x402_http_client ,
88- stream_usage = True ,
89- streaming = True ,
90- base_url = config .LLM_SERVER_URL ,
9132 )
9233
9334
9435def create_investor_executor () -> any :
95- openai_model = ChatOpenAI (
96- model = REASONING_MODEL ,
36+ model = og .agents .langchain_adapter (
37+ client = opengradient_client ,
38+ model_cid = REASONING_MODEL ,
9739 temperature = 0.1 ,
98- api_key = config .DUMMY_X402_API_KEY ,
99- http_async_client = x402_http_client ,
100- stream_usage = True ,
101- streaming = True ,
102- base_url = config .LLM_SERVER_URL ,
10340 max_tokens = 16384 ,
10441 )
10542
10643 agent_executor = create_react_agent (
107- model = openai_model , tools = create_investor_agent_toolkit ()
44+ model = model , tools = create_investor_agent_toolkit ()
10845 )
10946
11047 return agent_executor
@@ -114,23 +51,19 @@ def create_analytics_executor(
11451 token_metadata_repo : TokenMetadataRepo ,
11552 extra_tools : list = None ,
11653) -> any :
117- openai_model = ChatOpenAI (
118- model = REASONING_MODEL ,
54+ model = og .agents .langchain_adapter (
55+ client = opengradient_client ,
56+ model_cid = REASONING_MODEL ,
11957 temperature = 0.1 ,
12058 max_tokens = 16384 ,
121- api_key = config .DUMMY_X402_API_KEY ,
122- http_async_client = x402_http_client ,
123- stream_usage = True ,
124- streaming = True ,
125- base_url = config .LLM_SERVER_URL ,
12659 )
12760
12861 tools = create_analytics_agent_toolkit (token_metadata_repo )
12962 if extra_tools :
13063 tools .extend (extra_tools )
13164
13265 analytics_executor = create_react_agent (
133- model = openai_model ,
66+ model = model ,
13467 tools = tools ,
13568 )
13669
0 commit comments