Les invites système vous permettent de limiter le comportement de l’agent, d’ajouter un contexte spécifique à un domaine, ou de définir le ton et le style des réponses.
Par défaut, le SDK utilise une invite système intégrée qui fournit à l’agent ses capacités de base, y compris la modification de fichiers, la recherche de code et l’accès au shell. Vous pouvez soit remplacer entièrement cette invite, soit y ajouter des instructions supplémentaires.
Transmettez une chaîne à l’option systemPrompt pour remplacer entièrement l’invite système intégrée. Utilisez cette option lorsque vous avez besoin d’un contrôle total sur le comportement de l’agent et que vous ne souhaitez recevoir aucune instruction par défaut.
import{createCortexCodeSession}from"cortex-code-agent-sdk";constsession=awaitcreateCortexCodeSession({cwd:process.cwd(),systemPrompt:`You are a code review assistant.Prioritize finding bugs, security issues, and maintainability risks.Explain the issue and suggest concrete fixes.`,});
fromcortex_code_agent_sdkimportCortexCodeSDKClient,CortexCodeAgentOptionsasyncwithCortexCodeSDKClient(CortexCodeAgentOptions(system_prompt="""You are a code review assistant.Prioritize finding bugs, security issues, and maintainability risks.Explain the issue and suggest concrete fixes.""",))asclient:awaitclient.query("Review the auth module for security issues")asyncformsginclient.receive_response():pass
Avertissement
Le remplacement de l’invite par défaut supprime toutes les instructions intégrées, y compris les conseils sur l’utilisation des outils et les garde-fous de sécurité. Ne remplacez l’invite que lorsque vous avez besoin d’un accès total sur le comportement de l’agent.
Pour conserver les capacités intégrées tout en ajoutant vos propres instructions, utilisez un objet prédéfini d’invite système avec le champ append. Le nom prédéfini est implicite, de sorte que vous n’avez besoin que de {"type":"preset","append":...}. Cette opération permet d’ajouter vos instructions après l’invite système par défaut.
import{createCortexCodeSession}from"cortex-code-agent-sdk";constsession=awaitcreateCortexCodeSession({cwd:process.cwd(),systemPrompt:{type:"preset",append:"Focus on Python files. Always run pytest after making changes.",},});
fromcortex_code_agent_sdkimportCortexCodeSDKClient,CortexCodeAgentOptionsasyncwithCortexCodeSDKClient(CortexCodeAgentOptions(system_prompt={"type":"preset","append":"Focus on Python files. Always run pytest after making changes.",},))asclient:awaitclient.query("Fix the failing test in test_auth.py")asyncformsginclient.receive_response():pass
Les deux SDKs fournissent également un raccourci en mode ajout uniquement :
import{createCortexCodeSession}from"cortex-code-agent-sdk";constsession=awaitcreateCortexCodeSession({cwd:process.cwd(),appendSystemPrompt:"Focus on Python files. Always run pytest after making changes.",});
fromcortex_code_agent_sdkimportCortexCodeAgentOptionsoptions=CortexCodeAgentOptions(append_system_prompt="Focus on Python files. Always run pytest after making changes.",)
Encouragez l’agent à privilégier un comportement d’analyse préalable à l’examen du code :
import{createCortexCodeSession}from"cortex-code-agent-sdk";constsession=awaitcreateCortexCodeSession({cwd:process.cwd(),appendSystemPrompt:`You are a code reviewer. Follow these rules:- Prioritize reading code and analyzing behavior before proposing changes.- Do not modify files unless the user explicitly asks for an implementation.- Identify bugs, security issues, and style problems.- Provide specific line numbers and suggested fixes in your response.`,});
fromcortex_code_agent_sdkimportCortexCodeSDKClient,CortexCodeAgentOptionsasyncwithCortexCodeSDKClient(CortexCodeAgentOptions(system_prompt={"type":"preset","append":"""You are a code reviewer. Follow these rules:- Prioritize reading code and analyzing behavior before proposing changes.- Do not modify files unless the user explicitly asks for an implementation.- Identify bugs, security issues, and style problems.- Provide specific line numbers and suggested fixes in your response.""",},))asclient:...
Orientez l’agent vers une technologie ou un domaine particulier :
import{createCortexCodeSession}from"cortex-code-agent-sdk";constsession=awaitcreateCortexCodeSession({cwd:process.cwd(),appendSystemPrompt:`You are a SQL and database specialist working with Snowflake.- Write efficient SQL queries optimized for Snowflake's columnar storage.- Use Snowflake-specific features like VARIANT columns and FLATTEN.- Always include LIMIT clauses in exploratory queries.- Validate SQL syntax before suggesting changes.`,});
fromcortex_code_agent_sdkimportCortexCodeSDKClient,CortexCodeAgentOptionsasyncwithCortexCodeSDKClient(CortexCodeAgentOptions(system_prompt={"type":"preset","append":"""You are a SQL and database specialist working with Snowflake.- Write efficient SQL queries optimized for Snowflake's columnar storage.- Use Snowflake-specific features like VARIANT columns and FLATTEN.- Always include LIMIT clauses in exploratory queries.- Validate SQL syntax before suggesting changes.""",},))asclient:...
Assurez-vous que l’agent respecte les normes de codage spécifiques :
import{createCortexCodeSession}from"cortex-code-agent-sdk";constsession=awaitcreateCortexCodeSession({cwd:process.cwd(),appendSystemPrompt:`Enforce these coding standards in all changes:- Use TypeScript strict mode conventions.- Prefer const over let; never use var.- All functions must have explicit return types.- Use async/await instead of raw Promises.- Run "npm run lint" after every file change.`,});
fromcortex_code_agent_sdkimportCortexCodeSDKClient,CortexCodeAgentOptionsasyncwithCortexCodeSDKClient(CortexCodeAgentOptions(system_prompt={"type":"preset","append":"""Enforce these coding standards in all changes:- Follow PEP 8 style guidelines.- Use type hints for all function signatures.- Prefer f-strings over .format() or % formatting.- Run "ruff check" after every file change.""",},))asclient:...