1+ package io .rong .example .agent ;
2+
3+ import io .rong .CenterEnum ;
4+ import io .rong .RongCloud ;
5+ import io .rong .methods .agent .AIAgent ;
6+ import io .rong .models .agent .*;
7+ import io .rong .models .response .ChatAgentResult ;
8+ import io .rong .models .response .GetAIAgentResult ;
9+ import io .rong .models .response .PagingQueryAgentsResult ;
10+ import io .rong .models .response .ResponseResult ;
11+
12+ /**
13+ * AI agent test example
14+ *
15+ * @author RongCloud
16+ */
17+ public class AIAgentExample {
18+
19+
20+ /**
21+ * Replace with your App Key
22+ */
23+ private static final String APP_KEY = "appKey" ;
24+ /**
25+ * Replace with your App Secret
26+ */
27+ private static final String APP_SECRET = "secret" ;
28+ /**
29+ * Initialization
30+ */
31+ private static AIAgent agent = RongCloud .getInstance (APP_KEY , APP_SECRET , CenterEnum .BJ ).agent ;
32+
33+
34+ /**
35+ * Local test call
36+ *
37+ * @param args
38+ * @throws Exception
39+ */
40+ public static void main (String [] args ) throws Exception {
41+ // Create agent test
42+ createTest ();
43+ // Delete agent test
44+ deleteTest ();
45+ // Update agent test
46+ updateTest ();
47+ // Get agent test
48+ getTest ();
49+ // Query agent list test
50+ queryListTest ();
51+
52+ // Test chat
53+ chatTest ();
54+ }
55+
56+ private static void chatTest () throws Exception {
57+ ChatModel model = new ChatModel ();
58+ model .setAgentId ("test_agentg_3821633206" );
59+ model .setMemory (true );
60+ model .setConversationId ("test_id" );
61+ model .setUser ("uid1" );
62+ model .setQuery ("Hello" );
63+ ChatAgentResult result = agent .chat (model );
64+ System .out .println ("Chat to agent test: " + result .toString ());
65+ }
66+
67+ private static void createTest () throws Exception {
68+ AgentModel info = new AgentModel ();
69+ info .setAgentId ("rc_agentId" );
70+ info .setName ("rc_name" );
71+ info .setDescription ("rc_description" );
72+ info .setType ("chat" );
73+ info .setStatus ("active" );
74+ AgentConfig agentConfig = new AgentConfig ();
75+ Model model = new Model ();
76+ model .setProvider ("openai" );
77+ model .setName ("qwen-turbo" );
78+ ModelOptions modelOptions = new ModelOptions ();
79+ model .setOptions (modelOptions );
80+ agentConfig .setModel (model );
81+ Prompt prompt = new Prompt ();
82+ // prompt.setId("temp_id");
83+ agentConfig .setPrompt (prompt );
84+ Memory memory = new Memory ();
85+ memory .setStrategy ("sliding_window" );
86+ memory .setMaxMessages (10 );
87+ memory .setMaxTokens (1000 );
88+ agentConfig .setMemory (memory );
89+ info .setAgentConfig (agentConfig );
90+ ResponseResult result = agent .create (info );
91+ System .out .println ("create agent test: " + result .toString ());
92+ }
93+
94+ private static void getTest () throws Exception {
95+ GetAIAgentResult result = agent .get ("rc_agentId" );
96+ System .out .println ("update agent test: " + result .toString ());
97+ }
98+
99+ private static void deleteTest () throws Exception {
100+ ResponseResult result = agent .delete ("rc_agentId" );
101+ System .out .println ("delete agent test: " + result .toString ());
102+ }
103+
104+ private static void updateTest () throws Exception {
105+ AgentModel info = new AgentModel ();
106+ info .setAgentId ("rc_agentId" );
107+ info .setName ("rc_name111" );
108+ info .setDescription ("rc_description111" );
109+ info .setType ("chat" );
110+ info .setStatus ("active" );
111+ AgentConfig agentConfig = new AgentConfig ();
112+ Model model = new Model ();
113+ model .setProvider ("openai" );
114+ model .setName ("qwen-turbo" );
115+ ModelOptions modelOptions = new ModelOptions ();
116+ model .setOptions (modelOptions );
117+ agentConfig .setModel (model );
118+ Prompt prompt = new Prompt ();
119+ agentConfig .setPrompt (prompt );
120+ Memory memory = new Memory ();
121+ memory .setStrategy ("sliding_window" );
122+ memory .setMaxMessages (10 );
123+ memory .setMaxTokens (1000 );
124+ agentConfig .setMemory (memory );
125+ info .setAgentConfig (agentConfig );
126+ ResponseResult result = agent .update (info );
127+ System .out .println ("update agent test: " + result .toString ());
128+ }
129+
130+ private static void queryListTest () throws Exception {
131+ PagingQueryAgentsResult result = agent .query (1 , 2 , "active" , "chat" );
132+ System .out .println ("update agent test: " + result .toString ());
133+ }
134+
135+
136+ }
0 commit comments