Note
GitHub Copilot Extensions est en beta. Des modifications peuvent être apportées.
Les Copilot agents communiquent avec la plateforme Copilot sous la forme d’événements envoyés par le serveur (SSE). Plutôt que d’attendre que la plateforme Copilot demande une mise à jour à votre agent, ou vice versa, vous pouvez utiliser les SSE pour envoyer et recevoir des mises à jour de la plateforme en temps réel.
Pour en savoir plus sur les SSE, consultez Événements envoyés par le serveur dans la documentation mdn.
Envoi d’événements envoyés par le serveur
Votre agent ne doit envoyer qu’un seul SSE pour chaque interaction avec la plateforme Copilot. Il existe quatre SSE prédéfinis que votre agent peut envoyer :
copilot_confirmation
Le SSE copilot_confirmation
envoie à l’utilisateur une invite pour confirmer une action. Ce SSE est envoyée par le biais d’un type d’événement et d’un champ de données. Le code suivant donne un exemple de SSE copilot_confirmation
:
// event: copilot_confirmation data: { // Currently, `action` is the only supported value for `type` in `copilot_confirmation`. "type": "action", // Title of the confirmation dialog shown to the user. "title": "Turn off feature flag", // Confirmation message shown to the user. "message": "Are you sure you wish to turn off the `copilot` feature flag?", // Optional field for the agent to include any data needed to uniquely identify this confirmation and take action once the decision is received from the client. "confirmation": { "id": "id-123", "other": "identifier-as-needed", } }
event: copilot_confirmation
data: {
"type": "action",
Currently, action
is the only supported value for type
in copilot_confirmation
.
"title": "Turn off feature flag",
Title of the confirmation dialog shown to the user.
"message": "Are you sure you wish to turn off the `copilot` feature flag?",
Confirmation message shown to the user.
"confirmation": {
"id": "id-123",
"other": "identifier-as-needed",
}
}
Optional field for the agent to include any data needed to uniquely identify this confirmation and take action once the decision is received from the client.
//
event: copilot_confirmation
data: {
// Currently, `action` is the only supported value for `type` in `copilot_confirmation`.
"type": "action",
// Title of the confirmation dialog shown to the user.
"title": "Turn off feature flag",
// Confirmation message shown to the user.
"message": "Are you sure you wish to turn off the `copilot` feature flag?",
// Optional field for the agent to include any data needed to uniquely identify this confirmation and take action once the decision is received from the client.
"confirmation": {
"id": "id-123",
"other": "identifier-as-needed",
}
}
Une fois que l’utilisateur a accepté ou rejeté la confirmation, l’agent reçoit un message similaire à l’exemple suivant :
// { "copilot_confirmations": [ { // A string containing the state of the confirmation. This value is either `accepted` or `dismissed`. "state": "accepted", // An array of strings containing data identifying the relevant action. "confirmation": { "id": "id-123", "other": "identifier-as-needed", } } ] }
{
"copilot_confirmations": [
{
"state": "accepted",
A string containing the state of the confirmation. This value is either accepted
or dismissed
.
"confirmation": {
"id": "id-123",
"other": "identifier-as-needed",
}
}
]
}
An array of strings containing data identifying the relevant action.
//
{
"copilot_confirmations": [
{
// A string containing the state of the confirmation. This value is either `accepted` or `dismissed`.
"state": "accepted",
// An array of strings containing data identifying the relevant action.
"confirmation": {
"id": "id-123",
"other": "identifier-as-needed",
}
}
]
}
En fonction des valeurs de ce message, l’agent peut alors compléter ou annuler l’action appropriée.
copilot_errors
Le SSE copilot_errors
envoie à la plateforme Copilot une liste des erreurs rencontrées. Ce SSE est envoyée par le biais d’un type d’événement et d’un champ de données. Le code suivant donne un exemple de SSE copilot_errors
:
// event: copilot_errors data: [{ // A string that specifies the error's type. `type` can have a value of `reference`, `function` or `agent`. "type": "function", // A string controlled by the agent describing the nature of an error. "code": "recentchanges", // A string that specifies the error message shown to the user. "message": "The repository does not exist", // A string that serves as a unique identifier to link the error with other resources such as references or function calls. "identifier": "github/hello-world" }]
event: copilot_errors
data: [{
"type": "function",
A string that specifies the error's type. type
can have a value of reference
, function
or agent
.
"code": "recentchanges",
A string controlled by the agent describing the nature of an error.
"message": "The repository does not exist",
A string that specifies the error message shown to the user.
"identifier": "github/hello-world"
}]
A string that serves as a unique identifier to link the error with other resources such as references or function calls.
//
event: copilot_errors
data: [{
// A string that specifies the error's type. `type` can have a value of `reference`, `function` or `agent`.
"type": "function",
// A string controlled by the agent describing the nature of an error.
"code": "recentchanges",
// A string that specifies the error message shown to the user.
"message": "The repository does not exist",
// A string that serves as a unique identifier to link the error with other resources such as references or function calls.
"identifier": "github/hello-world"
}]
copilot_references
Le SSE copilot_references
envoie à l’utilisateur une liste de références utilisées pour générer une réponse. Ce SSE est envoyée par le biais d’un type d’événement et d’un champ de données. Le code suivant donne un exemple de SSE copilot_references
:
// event: copilot_references data: [{ // A string that specifies the type of the reference. "type": "blackbeard.story", // A string that specifies the ID of the reference. "id": "snippet", // An optional field where the agent can include any data needed to uniquely identify this reference. "data": { "file": "story.go", "start": "0", "end": "13", "content": "func main()...writeStory()..." }, // An optional boolean that indicates if the reference was passed implicitly or explicitly. "is_implicit": false, // An optional field for the agent to include any metadata to display in the user's environment. If any of the below required fields are missing, then the reference will not be rendered in the UI. "metadata": { "display_name": "Lines 1-13 from story.go", "display_icon": "icon", "display_url": "http://blackbeard.com/story/1", } }]
event: copilot_references
data: [{
"type": "blackbeard.story",
A string that specifies the type of the reference.
"id": "snippet",
A string that specifies the ID of the reference.
"data": {
"file": "story.go",
"start": "0",
"end": "13",
"content": "func main()...writeStory()..."
},
An optional field where the agent can include any data needed to uniquely identify this reference.
"is_implicit": false,
An optional boolean that indicates if the reference was passed implicitly or explicitly.
"metadata": {
"display_name": "Lines 1-13 from story.go",
"display_icon": "icon",
"display_url": "http://blackbeard.com/story/1",
}
}]
An optional field for the agent to include any metadata to display in the user's environment. If any of the below required fields are missing, then the reference will not be rendered in the UI.
//
event: copilot_references
data: [{
// A string that specifies the type of the reference.
"type": "blackbeard.story",
// A string that specifies the ID of the reference.
"id": "snippet",
// An optional field where the agent can include any data needed to uniquely identify this reference.
"data": {
"file": "story.go",
"start": "0",
"end": "13",
"content": "func main()...writeStory()..."
},
// An optional boolean that indicates if the reference was passed implicitly or explicitly.
"is_implicit": false,
// An optional field for the agent to include any metadata to display in the user's environment. If any of the below required fields are missing, then the reference will not be rendered in the UI.
"metadata": {
"display_name": "Lines 1-13 from story.go",
"display_icon": "icon",
"display_url": "http://blackbeard.com/story/1",
}
}]
SSE par défaut
Le SSE par défaut envoie à l’utilisateur un message de conversation général. Ce SSE n’est pas de nom et est envoyé uniquement via un champ de données. Le code suivant donne un exemple de SSE par défaut :
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0125", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}
Réception d’événements envoyés par le serveur
Tout comme votre agent envoie des SSE à la plateforme Copilot, il reçoit également le SSE resp_message
de la plateforme. Ce SSE contient une liste de messages de l’utilisateur, ainsi que des données facultatives relatives à chacun des événements SSE que l’agent peut envoyer. Consultez l’exemple de code suivant pour obtenir un exemple de demande curl à votre agent contenant un message :
curl --request POST \
--url $AGENT_URL \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header "X-GitHub-Token: $RUNTIME_GENERATED_TOKEN" \
--data '{
"messages": [
{
"role": "user",
"content": "What is a closure in javascript?",
"copilot_references": []
}
]
}'
Étapes suivantes
Maintenant que vous comprenez comment votre Copilot agent communique avec la plateforme Copilot, vous pouvez apprendre à intégrer votre agent avec l’API GitHub. Consultez « Configuring your Copilot agent to communicate with GitHub ».