session_id, which can be used for subsequent resumption.system, which contains the session_id.import { query } from '@tencent-ai/agent-sdk';let sessionId: string | undefined;const q = query({prompt: 'Help me build a Web application',options: {model: 'deepseek-v3.1'}});for await (const message of q) {// Obtain the session_id from the initialization messageif (message.type === 'system' && message.subtype === 'init') {sessionId = message.session_id;console.log(`Session ID: ${sessionId}`);// Save the sessionId for later resumption.}console.log(message);}// The sessionId can be saved to a database or a file.
import asynciofrom codebuddy_agent_sdk import query, CodeBuddyAgentOptions, SystemMessagesession_id = Noneasync def main():global session_idoptions = CodeBuddyAgentOptions(model="deepseek-v3.1")async for message in query(prompt="Help me build a Web application", options=options):# Obtain the session_id from the initialization messageif isinstance(message, SystemMessage):session_id = message.data.get("session_id")print(f"Session ID: {session_id}")# Save the session_id for later resumption.print(message)asyncio.run(main())# The session_id can be saved to a database or a file.
import { unstable_v2_createSession } from '@tencent-ai/agent-sdk';const session = unstable_v2_createSession({model: 'deepseek-v3.1'});await session.send('Help me build a Web application');for await (const message of session.stream()) {if (message.type === 'system' && message.subtype === 'init') {console.log(`Session ID: ${message.session_id}`);}console.log(message);}// Use session.sessionId to obtain it (available after initialization).console.log(`Session ID: ${session.sessionId}`);session.close();
from codebuddy_agent_sdk import CodeBuddySDKClient, CodeBuddyAgentOptionsasync def main():options = CodeBuddyAgentOptions(model="deepseek-v3.1")async with CodeBuddySDKClient(options=options) as client:await client.query("Help me build a Web application")async for message in client.receive_response():if isinstance(message, SystemMessage):print(f"Session ID: {message.data.get('session_id')}")print(message)
session_id to resume the session and continue the previous conversation.import { query } from '@tencent-ai/agent-sdk';// Use the previously saved session_id.const savedSessionId = 'abc123-xyz789';const q = query({prompt: 'Continue our previous work',options: {model: 'deepseek-v3.1',resume: savedSessionId // Resume the specified session}});for await (const message of q) {console.log(message);}
import { unstable_v2_resumeSession } from '@tencent-ai/agent-sdk';// Use the previously saved session_id.const savedSessionId = 'abc123-xyz789';const session = unstable_v2_resumeSession(savedSessionId, {model: 'deepseek-v3.1'});await session.send('Continue our previous work');for await (const message of session.stream()) {console.log(message);}session.close();
from codebuddy_agent_sdk import query, CodeBuddyAgentOptions# Use the previously saved session_id.saved_session_id = "abc123-xyz789"options = CodeBuddyAgentOptions(model="deepseek-v3.1",resume=saved_session_id # Resume the specified session)async for message in query(prompt="Continue our previous work", options=options):print(message)
continue / continue_conversation option to automatically continue the most recent session:const q = query({prompt: 'Continue',options: {model: 'deepseek-v3.1',continue: true // Continue the most recent session}});
options = CodeBuddyAgentOptions(model="deepseek-v3.1",continue_conversation=True # Continue the most recent session)
resume to resume the session:import { query } from '@tencent-ai/agent-sdk';async function multiTurnWithQuery() {let sessionId: string;// First round of conversationconst q1 = query({prompt: 'Help me create a React project',options: { model: 'deepseek-v3.1' }});for await (const msg of q1) {if (msg.type === 'system' && msg.subtype === 'init') {sessionId = msg.session_id;}if (msg.type === 'result') {console.log('First round completed');}}// Second round of conversation (resume the session)const q2 = query({prompt: 'Add a user login page',options: {model: 'deepseek-v3.1',resume: sessionId}});for await (const msg of q2) {if (msg.type === 'result') {console.log('Second round completed');}}// Third round of conversationconst q3 = query({prompt: 'Add form validation',options: {model: 'deepseek-v3.1',resume: sessionId}});for await (const msg of q3) {console.log(msg);}}
import { unstable_v2_createSession } from '@tencent-ai/agent-sdk';async function multiTurnWithSession() {const session = unstable_v2_createSession({model: 'deepseek-v3.1'});try {// First round of conversationawait session.send('Help me create a React project');for await (const msg of session.stream()) {console.log(msg);}// Second round of conversation (context is automatically maintained)await session.send('Add a user login page');for await (const msg of session.stream()) {console.log(msg);}// Third round of conversationawait session.send('Add form validation');for await (const msg of session.stream()) {console.log(msg);}} finally {session.close();}}
from codebuddy_agent_sdk import CodeBuddySDKClient, CodeBuddyAgentOptionsasync def multi_turn_conversation():options = CodeBuddyAgentOptions(model="deepseek-v3.1")async with CodeBuddySDKClient(options=options) as client:# First Round of Conversationawait client.query("Help me create a React project")async for msg in client.receive_response():print(msg)# Second Round of Conversation (Context Is Automatically Maintained)await client.query("Add a user login page")async for msg in client.receive_response():print(msg)# Third Round of Conversationawait client.query("Add form validation")async for msg in client.receive_response():print(msg)
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback