a2a: a contextId keeps the conversation on the server
The server keeps up to 16 conversations, keyed by contextId and evicted LRU-style. A message with a known id continues it; without one the server generates an id and returns it in the task, so callers that send no context at all do not share a history. The session log still records every turn. test_a2a_context.sh uses a fake OpenAI endpoint that answers with the number of user messages it received: fresh=1, same context=2, another context=1, and continuing with the generated id reaches 2. README, PLUGINS.md, TODO, ROADMAP and the site follow.
This commit is contained in:
1 parent
9389793402
commit
968b5eada4
12 files changed
+252
-49
No files matched your search
@@ -221,6 +221,7 @@ check: $(LIB) $(BIN) $(PLUGIN) $(TESTS)
|
||||
echo "== tests/test_a2a.sh"; sh tests/test_a2a.sh; \
|
||||
echo "== tests/test_a2a_ui.sh"; sh tests/test_a2a_ui.sh; \
|
||||
echo "== tests/test_a2a_server.sh"; sh tests/test_a2a_server.sh; \
|
||||
echo "== tests/test_a2a_context.sh"; sh tests/test_a2a_context.sh; \
|
||||
echo "== tests/test_ui.sh"; sh tests/test_ui.sh; \
|
||||
echo "all tests passed"
|
||||
|
||||
|
||||
@@ -134,8 +134,9 @@ SPLINTER_A2A_SERVER_TOKEN=... \
|
||||
Another agent can send `SendMessage` to `POST /a2a` and read `GetTask` or
|
||||
`ListTasks`; the
|
||||
agent card is served at `/.well-known/agent-card.json`. `SendStreamingMessage`
|
||||
streams the answer as SSE artifact updates, then a completed status. Each
|
||||
request runs one turn in its own conversation. File parts, push notifications,
|
||||
streams the answer as SSE artifact updates, then a completed status. A
|
||||
`contextId` is a conversation: the next message with it continues. Without one
|
||||
the server creates a context and returns it in the task. File parts, push notifications,
|
||||
`CancelTask` and continuation of an interrupted task are refused with a JSON-RPC
|
||||
error rather than half-answered. Beyond loopback the bearer token is required;
|
||||
there is no TLS, so put it behind ssh or a tunnel.
|
||||
|
||||
@@ -48,14 +48,15 @@ Context bleibt. `SPLINTER_A2A_CARD` findet den Endpunkt ueber die Agent Card.
|
||||
|
||||
Der Server ist gebaut: `src/a2aserver.c`, `POST /a2a` mit `SendMessage` (ein
|
||||
Turn in eigener Konversation, completed Task), `SendStreamingMessage` (SSE,
|
||||
`artifactUpdate`-Chunks, dann completed `statusUpdate`) `GetTask`, `ListTasks`,
|
||||
`artifactUpdate`-Chunks, dann completed `statusUpdate`) `GetTask`, `ListTasks`, Multiturn ueber `contextId`,
|
||||
`GET /.well-known/agent-card.json`, Bearer-Token ueber
|
||||
`SPLINTER_A2A_SERVER_TOKEN` jenseits von Loopback.
|
||||
|
||||
Offen: Datei- und strukturierte Teile, Push-Notifications,
|
||||
`CancelTask`/`SubscribeToTask` und die Fortsetzung eines unterbrochenen Tasks.
|
||||
`CancelTask`/`SubscribeToTask` und die Fortsetzung eines unterbrochenen Tasks
|
||||
(`INPUT_REQUIRED`).
|
||||
|
||||
Naechster Schritt: Multiturn (Task-Fortsetzung), danach Datei-Teile.
|
||||
Naechster Schritt: Datei-Teile.
|
||||
|
||||
### 4. `~/.local/lib` enthaelt Fremdlast
|
||||
|
||||
@@ -96,10 +97,12 @@ Naechster Schritt: entscheiden, ob die npm-Reste weg duerfen. Kein Code.
|
||||
(JSON-RPC 2.0, Text, blockierend), in der UI `SendStreamingMessage` (SSE,
|
||||
Artefakt-Text live) und findet den Endpunkt ueber `SPLINTER_A2A_CARD`;
|
||||
`src/a2aserver.c` serviert `SendMessage`, `SendStreamingMessage` (SSE),
|
||||
`GetTask`, `ListTasks` und die Agent Card mit Bearer-Token. `tests/test_a2a.sh` prueft Task, Message, Token, Fehler,
|
||||
`GetTask`, `ListTasks`, Multiturn ueber `contextId` und die Agent Card mit
|
||||
Bearer-Token. `tests/test_a2a.sh` prueft Task, Message, Token, Fehler,
|
||||
Streaming und Discovery, `tests/test_a2a_ui.sh` den Streaming-Pfad,
|
||||
`tests/test_a2a_server.sh` den Server und den Client gegen den Server
|
||||
(Discovery, blockierend und streamend).
|
||||
(Discovery, blockierend und streamend), `tests/test_a2a_context.sh` die
|
||||
Konversation ueber `contextId`.
|
||||
- **Fehler dabei gefunden und behoben**: `delegate_retry` las `id` und `force`
|
||||
in denselben Puffer; `json_str` haengt an, also wurde aus `job-1` mit
|
||||
`force=1` die Id `job-11` (`src/delegate.c`, `tool_delegate_retry`).
|
||||
|
||||
+3
-2
@@ -312,8 +312,9 @@ needs the agent and its authorization model, not only a transport.
|
||||
SPLINTER_A2A_SERVER_TOKEN=... \
|
||||
splinter --a2a-server-listen 127.0.0.1 --a2a-listen-port 8099
|
||||
|
||||
`POST /a2a` speaks JSON-RPC: `SendMessage` runs one turn in a fresh conversation
|
||||
(system prompt plus the caller's text), stores the completed Task and returns it;
|
||||
`POST /a2a` speaks JSON-RPC: `SendMessage` runs one turn in the conversation
|
||||
named by `contextId` (or a fresh one, whose id comes back in the task), stores
|
||||
the completed Task and returns it;
|
||||
`SendStreamingMessage` runs the same turn and writes SSE `artifactUpdate` events
|
||||
as the transport produces text (a non-streaming transport sends its whole answer
|
||||
as one artifact), followed by a completed `statusUpdate`; `GetTask` returns a
|
||||
|
||||
+4
-3
@@ -5,9 +5,10 @@ Stand: 2026-11-09. Die geprüfte, ausführliche Liste mit Belegen steht in
|
||||
|
||||
1. **A2A: was noch fehlt** — Client (`SendMessage`, `SendStreamingMessage` in
|
||||
der UI, Agent-Card-Discovery) und Server (`SendMessage`, SSE-Streaming,
|
||||
`GetTask`, `ListTasks`, Agent Card) stehen, alles mit Text. Offen sind Datei- und
|
||||
strukturierte Teile, Push-Notifications, `CancelTask`/`SubscribeToTask` und
|
||||
die Fortsetzung eines unterbrochenen Tasks. `swarm` ist nur lokale IPC im
|
||||
`GetTask`, `ListTasks`, Multiturn ueber `contextId`, Agent Card) stehen, alles
|
||||
mit Text. Offen sind Datei- und strukturierte Teile, Push-Notifications,
|
||||
`CancelTask`/`SubscribeToTask` und die Fortsetzung eines unterbrochenen
|
||||
Tasks. `swarm` ist nur lokale IPC im
|
||||
selben Verzeichnis, kein A2A.
|
||||
|
||||
2. **Echte Gegenstellen** — die Kids-Zustimmung gegen einen echten Telegram-Bot
|
||||
|
||||
+101
-22
@@ -18,9 +18,10 @@
|
||||
* with half a protocol. Streaming is served: SendStreamingMessage writes
|
||||
* artifactUpdate and statusUpdate events over SSE.
|
||||
*
|
||||
* One turn per request, one connection at a time. The conversation is local to
|
||||
* the request (the system prompt plus the caller's text), so two remote agents
|
||||
* cannot read each other's history through a shared conversation.
|
||||
* One turn per request, one connection at a time. A contextId is a
|
||||
* conversation: the next message with the same id continues it. Without one,
|
||||
* the server makes an id up and returns it in the task, so two clients that
|
||||
* send no context at all do not share a history.
|
||||
*
|
||||
* Authorization: a token is required beyond loopback. It arrives as
|
||||
* `Authorization: Bearer <token>` and is compared against
|
||||
@@ -46,6 +47,7 @@
|
||||
#include "a2aserver.h"
|
||||
|
||||
#define A2A_TASKS 32
|
||||
#define A2A_CONTEXTS 16
|
||||
#define HDR_MAX 16384
|
||||
#define BODY_MAX (1 << 20)
|
||||
|
||||
@@ -56,8 +58,24 @@ struct a2a_task {
|
||||
struct sp_buf answer;
|
||||
};
|
||||
|
||||
/*
|
||||
* A context is a conversation, not a task: the next message with the same
|
||||
* contextId continues it. Without a contextId the server makes one up and
|
||||
* returns it in the task, so two clients that send no context at all do not
|
||||
* share a history.
|
||||
*/
|
||||
struct a2a_ctx {
|
||||
int used;
|
||||
char id[128];
|
||||
unsigned long last;
|
||||
struct sp_conv conv;
|
||||
};
|
||||
|
||||
static struct a2a_task g_tasks[A2A_TASKS];
|
||||
static struct a2a_ctx g_ctx[A2A_CONTEXTS];
|
||||
static unsigned g_seq;
|
||||
static unsigned g_ctx_seq;
|
||||
static unsigned long g_clock;
|
||||
static volatile int g_stop;
|
||||
|
||||
static void
|
||||
@@ -304,6 +322,49 @@ task_store(const char *context, const struct sp_buf *answer)
|
||||
return task_store_id(NULL, context, answer);
|
||||
}
|
||||
|
||||
static struct a2a_ctx *
|
||||
ctx_get(struct sp_agent *ag, const char *id, int create)
|
||||
{
|
||||
size_t i, slot = A2A_CONTEXTS, oldest = 0;
|
||||
unsigned long old = ~0UL;
|
||||
|
||||
for (i = 0; i < A2A_CONTEXTS; i++) {
|
||||
if (g_ctx[i].used && strcmp(g_ctx[i].id, id) == 0) {
|
||||
g_ctx[i].last = ++g_clock;
|
||||
return &g_ctx[i];
|
||||
}
|
||||
if (!g_ctx[i].used && slot == A2A_CONTEXTS)
|
||||
slot = i;
|
||||
if (g_ctx[i].used && g_ctx[i].last < old) {
|
||||
old = g_ctx[i].last;
|
||||
oldest = i;
|
||||
}
|
||||
}
|
||||
if (!create)
|
||||
return NULL;
|
||||
if (slot == A2A_CONTEXTS)
|
||||
slot = oldest;
|
||||
{
|
||||
struct a2a_ctx *c = &g_ctx[slot];
|
||||
|
||||
if (c->used)
|
||||
sp_conv_free(&c->conv);
|
||||
memset(c, 0, sizeof(*c));
|
||||
sp_conv_init(&c->conv);
|
||||
if (ag->cfg != NULL && ag->cfg->system_prompt != NULL &&
|
||||
ag->cfg->system_prompt[0] != '\0' &&
|
||||
sp_conv_push(&c->conv, "system", NULL,
|
||||
ag->cfg->system_prompt) != 0) {
|
||||
sp_conv_free(&c->conv);
|
||||
return NULL;
|
||||
}
|
||||
snprintf(c->id, sizeof(c->id), "%s", id);
|
||||
c->used = 1;
|
||||
c->last = ++g_clock;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
task_obj(struct sp_buf *b, const struct a2a_task *t)
|
||||
{
|
||||
@@ -363,25 +424,16 @@ rpc_result(int fd, const char *id, const char *result)
|
||||
* history.
|
||||
*/
|
||||
static int
|
||||
run_turn(struct sp_agent *ag, const char *text, struct sp_buf *answer,
|
||||
struct sp_buf *err)
|
||||
run_turn(struct sp_agent *ag, struct sp_conv *conv, const char *text,
|
||||
struct sp_buf *answer, struct sp_buf *err)
|
||||
{
|
||||
struct sp_conv conv;
|
||||
struct sp_conv *saved;
|
||||
int rc;
|
||||
|
||||
sp_conv_init(&conv);
|
||||
if (ag->cfg != NULL && ag->cfg->system_prompt != NULL &&
|
||||
ag->cfg->system_prompt[0] != '\0' &&
|
||||
sp_conv_push(&conv, "system", NULL, ag->cfg->system_prompt) != 0) {
|
||||
sp_conv_free(&conv);
|
||||
return -1;
|
||||
}
|
||||
saved = ag->conv;
|
||||
ag->conv = &conv;
|
||||
ag->conv = conv;
|
||||
rc = sp_agent_run(ag, text, answer, err);
|
||||
ag->conv = saved;
|
||||
sp_conv_free(&conv);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -501,6 +553,8 @@ handle_stream(int fd, struct sp_agent *ag, const char *id,
|
||||
struct sp_buf text, answer, err;
|
||||
struct sp_agent_config cfg;
|
||||
const struct sp_agent_config *saved;
|
||||
struct a2a_ctx *cx;
|
||||
char ctxbuf[128];
|
||||
int rc;
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
@@ -529,19 +583,29 @@ handle_stream(int fd, struct sp_agent *ag, const char *id,
|
||||
goto out;
|
||||
}
|
||||
ctx = mcp_arg_string(message, "contextId");
|
||||
snprintf(o.context, sizeof(o.context), "%s",
|
||||
ctx != NULL && *ctx != '\0' ? ctx : "ctx-local");
|
||||
if (ctx == NULL || *ctx == '\0') {
|
||||
snprintf(ctxbuf, sizeof(ctxbuf), "ctx-%d-%u", (int)getpid(),
|
||||
++g_ctx_seq);
|
||||
ctx = ctxbuf;
|
||||
}
|
||||
snprintf(o.context, sizeof(o.context), "%s", ctx);
|
||||
if (ag->cfg == NULL) {
|
||||
sse_error(&o, -32603, "no agent configuration");
|
||||
goto out;
|
||||
}
|
||||
cx = ctx_get(ag, ctx, 1);
|
||||
if (cx == NULL) {
|
||||
sse_error(&o, -32603, "out of memory for a context");
|
||||
goto out;
|
||||
}
|
||||
sse_task(&o, "TASK_STATE_WORKING");
|
||||
saved = ag->cfg;
|
||||
cfg = *ag->cfg;
|
||||
cfg.stream = sse_text;
|
||||
cfg.stream_ctx = &o;
|
||||
ag->cfg = &cfg;
|
||||
rc = run_turn(ag, text.p != NULL ? text.p : "", &answer, &err);
|
||||
rc = run_turn(ag, &cx->conv, text.p != NULL ? text.p : "", &answer,
|
||||
&err);
|
||||
ag->cfg = saved;
|
||||
if (rc != 0) {
|
||||
sse_error(&o, -32603, err.p != NULL && err.len > 0 ?
|
||||
@@ -570,8 +634,9 @@ handle_rpc(int fd, struct sp_agent *ag, const char *payload)
|
||||
mcp_json *v;
|
||||
const mcp_json *params, *message, *parts;
|
||||
const char *method, *ctx;
|
||||
char id[128];
|
||||
char id[128], ctxbuf[128];
|
||||
struct sp_buf text, answer, err, out;
|
||||
struct a2a_ctx *cx;
|
||||
int rc;
|
||||
|
||||
json_id(payload, id, sizeof(id));
|
||||
@@ -604,9 +669,18 @@ handle_rpc(int fd, struct sp_agent *ag, const char *payload)
|
||||
goto send_out;
|
||||
}
|
||||
ctx = mcp_arg_string(message, "contextId");
|
||||
if (ctx == NULL || *ctx == '\0')
|
||||
ctx = "ctx-local";
|
||||
rc = run_turn(ag, text.p != NULL ? text.p : "", &answer, &err);
|
||||
if (ctx == NULL || *ctx == '\0') {
|
||||
snprintf(ctxbuf, sizeof(ctxbuf), "ctx-%d-%u",
|
||||
(int)getpid(), ++g_ctx_seq);
|
||||
ctx = ctxbuf;
|
||||
}
|
||||
cx = ctx_get(ag, ctx, 1);
|
||||
if (cx == NULL) {
|
||||
rpc_error(fd, id, -32603, "out of memory for a context");
|
||||
goto send_out;
|
||||
}
|
||||
rc = run_turn(ag, &cx->conv, text.p != NULL ? text.p : "",
|
||||
&answer, &err);
|
||||
if (rc != 0) {
|
||||
rpc_error(fd, id, -32603,
|
||||
err.p != NULL && err.len > 0 ? err.p :
|
||||
@@ -840,6 +914,11 @@ sp_a2a_serve(struct sp_agent *ag, const char *ip, int port, struct sp_buf *err)
|
||||
sp_buf_free(&g_tasks[i].answer);
|
||||
g_tasks[i].used = 0;
|
||||
}
|
||||
for (i = 0; i < A2A_CONTEXTS; i++)
|
||||
if (g_ctx[i].used) {
|
||||
sp_conv_free(&g_ctx[i].conv);
|
||||
g_ctx[i].used = 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "splinter: A2A server stopped\n");
|
||||
return 0;
|
||||
|
||||
@@ -53,7 +53,7 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<h1>splinter<span>_</span></h1>
|
||||
<p class="lead">An agent harness you own: chat in the terminal, tools with authorization classes, plugins, any model that speaks OpenAI — built by us so we can change it, instead of getting used to how somebody else's client behaves.</p>
|
||||
|
||||
<p class="meta"><b>23690</b> lines of C99/POSIX ·
|
||||
<p class="meta"><b>23769</b> lines of C99/POSIX ·
|
||||
<b>23</b> tools · <b>31</b> test programs ·
|
||||
<b>16</b> plugins · <b>42</b> palettes · BSD-3-Clause</p>
|
||||
|
||||
@@ -208,8 +208,8 @@ itself:</p>
|
||||
splinter: A2A server on 127.0.0.1:8099 (token required)</pre>
|
||||
<p><code>POST /a2a</code> takes <code>SendMessage</code>, <code>SendStreamingMessage</code>
|
||||
(SSE), <code>GetTask</code> and <code>ListTasks</code> as JSON-RPC; the agent card lives at
|
||||
<code>/.well-known/agent-card.json</code>. One turn per request, its own
|
||||
conversation. Beyond loopback the bearer token is required.</p>
|
||||
<code>/.well-known/agent-card.json</code>. A <code>contextId</code> is a
|
||||
conversation; without one the server makes one and returns it. Beyond loopback the bearer token is required.</p>
|
||||
|
||||
<h2>Kid mode</h2>
|
||||
<p>With the <code>kids</code> plugin every change needs a parent's approval
|
||||
|
||||
+3
-3
@@ -53,7 +53,7 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<h1>splinter<span>_</span></h1>
|
||||
<p class="lead">Ein Agent-Harness, das dir gehoert: Chat im Terminal, Werkzeuge mit Autorisierungsklassen, Plugins, jedes Modell das OpenAI spricht — von uns gebaut, damit wir es umbauen koennen, statt uns an das Verhalten eines fremden Clients zu gewoehnen.</p>
|
||||
|
||||
<p class="meta"><b>23690</b> Zeilen C99/POSIX ·
|
||||
<p class="meta"><b>23769</b> Zeilen C99/POSIX ·
|
||||
<b>23</b> Werkzeuge · <b>31</b> Test-Programme ·
|
||||
<b>16</b> Plugins · <b>42</b> Farbschemata · BSD-3-Clause</p>
|
||||
|
||||
@@ -209,8 +209,8 @@ sich selbst hin:</p>
|
||||
splinter: A2A server on 127.0.0.1:8099 (token required)</pre>
|
||||
<p><code>POST /a2a</code> nimmt <code>SendMessage</code>, <code>SendStreamingMessage</code>
|
||||
(SSE), <code>GetTask</code> und <code>ListTasks</code> als JSON-RPC; die Agent Card liegt unter
|
||||
<code>/.well-known/agent-card.json</code>. Ein Turn pro Anfrage, eigene
|
||||
Konversation. Jenseits von Loopback ist der Bearer-Token Pflicht.</p>
|
||||
<code>/.well-known/agent-card.json</code>. Ein <code>contextId</code> ist eine
|
||||
Konversation; ohne eines legt der Server eins an und gibt es zurueck. Jenseits von Loopback ist der Bearer-Token Pflicht.</p>
|
||||
|
||||
<h2>Kindermodus</h2>
|
||||
<p>Mit dem Plugin <code>kids</code> braucht jede Aenderung die Zustimmung eines
|
||||
|
||||
@@ -53,7 +53,7 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<h1>splinter<span>_</span></h1>
|
||||
<p class="lead">Um harness de agente que e seu: chat no terminal, ferramentas com classes de autorizacao, plugins, qualquer modelo que fale OpenAI - escrito por nos para poder mudar-lo, em vez de nos acostumar com o comportamento de um cliente alheio.</p>
|
||||
|
||||
<p class="meta"><b>23690</b> linhas C99/POSIX ·
|
||||
<p class="meta"><b>23769</b> linhas C99/POSIX ·
|
||||
<b>23</b> ferramentas · <b>31</b> programas de teste ·
|
||||
<b>16</b> plugins · <b>42</b> paletas · BSD-3-Clause</p>
|
||||
|
||||
@@ -156,8 +156,8 @@ si mesmo:</p>
|
||||
splinter: A2A server on 127.0.0.1:8099 (token required)</pre>
|
||||
<p><code>POST /a2a</code> aceita <code>SendMessage</code>, <code>SendStreamingMessage</code>
|
||||
(SSE), <code>GetTask</code> e <code>ListTasks</code> em JSON-RPC; o agent card fica em
|
||||
<code>/.well-known/agent-card.json</code>. Um turno por requisicao, conversa
|
||||
propria. Fora do loopback o token Bearer e obrigatorio.</p>
|
||||
<code>/.well-known/agent-card.json</code>. Um <code>contextId</code> e uma conversa;
|
||||
sem ele o servidor cria um e devolve. Fora do loopback o token Bearer e obrigatorio.</p>
|
||||
|
||||
<hr>
|
||||
<p id="foot">splinter - C99/POSIX, BSD-3-Clause. Manual: <code>man ./docs/splinter.1</code> · ABI de plugins: <code>docs/PLUGINS.md</code></p>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# fake OpenAI endpoint for tests/test_a2a_context.sh.
|
||||
# Answers "users=N", where N is the number of role=user messages in the
|
||||
# request. That is how the test sees whether a context kept its history.
|
||||
import http.server, json, sys
|
||||
|
||||
|
||||
class H(http.server.BaseHTTPRequestHandler):
|
||||
def log_message(self, *a):
|
||||
pass
|
||||
|
||||
def do_POST(self):
|
||||
n = int(self.headers.get("Content-Length", 0))
|
||||
req = json.loads(self.rfile.read(n))
|
||||
users = sum(1 for m in req.get("messages", [])
|
||||
if m.get("role") == "user")
|
||||
text = "users=%d" % users
|
||||
if req.get("stream"):
|
||||
chunks = [
|
||||
{"choices": [{"delta": {"content": text}}]},
|
||||
{"choices": [{"delta": {}, "finish_reason": "stop"}]},
|
||||
]
|
||||
b = "".join("data: " + json.dumps(c) + "\n\n"
|
||||
for c in chunks) + "data: [DONE]\n\n"
|
||||
ctype = "text/event-stream"
|
||||
else:
|
||||
b = json.dumps({
|
||||
"id": "fake",
|
||||
"choices": [{"index": 0,
|
||||
"message": {"role": "assistant",
|
||||
"content": text},
|
||||
"finish_reason": "stop"}],
|
||||
"usage": {"prompt_tokens": 1, "completion_tokens": 1},
|
||||
}).encode()
|
||||
ctype = "application/json"
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", ctype)
|
||||
self.send_header("Content-Length", str(len(b)))
|
||||
self.end_headers()
|
||||
self.wfile.write(b)
|
||||
|
||||
|
||||
http.server.ThreadingHTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
# splinter -- A2A multi-turn: a contextId keeps the conversation.
|
||||
#
|
||||
# The fake model answers with the number of user messages it received. A fresh
|
||||
# context must see 1, the same context again 2, another context 1. A request
|
||||
# without a contextId gets one generated by the server, and continuing with
|
||||
# that id also reaches 2.
|
||||
set -u
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-a2a-ctx-XXXXXX") || exit 1
|
||||
P0=$((20000 + ($$ % 20000)))
|
||||
P1=$((P0 + 1))
|
||||
F0=
|
||||
F1=
|
||||
cleanup() {
|
||||
[ -n "$F0" ] && kill "$F0" 2>/dev/null
|
||||
[ -n "$F1" ] && kill "$F1" 2>/dev/null
|
||||
rm -rf "$D"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
mkdir -p "$D/home"
|
||||
|
||||
fails=0
|
||||
check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
|
||||
wait_port() {
|
||||
for i in $(seq 1 50); do
|
||||
curl -s -o /dev/null "http://127.0.0.1:$1/" && return 0
|
||||
sleep 0.2
|
||||
done
|
||||
return 1
|
||||
}
|
||||
send() { # send <context-json-or-empty> <text>
|
||||
ctx=$1
|
||||
if [ -n "$ctx" ]; then
|
||||
params="\"contextId\":\"$ctx\","
|
||||
else
|
||||
params=""
|
||||
fi
|
||||
curl -s -H 'Content-Type: application/json' --data \
|
||||
"{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"method\":\"SendMessage\",\"params\":{\"message\":{\"messageId\":\"m\",\"role\":\"ROLE_USER\",$params\"parts\":[{\"text\":\"$2\"}]}}}" \
|
||||
"http://127.0.0.1:$P1/a2a"
|
||||
}
|
||||
answer() { printf '%s' "$1" | grep -o 'users=[0-9]*' | head -1; }
|
||||
context_of() {
|
||||
printf '%s' "$1" | python3 -c \
|
||||
'import json,sys; print(json.load(sys.stdin)["result"]["task"]["contextId"])'
|
||||
}
|
||||
|
||||
python3 -I tests/fake_openai_count.py "$P0" &
|
||||
F0=$!
|
||||
check wait_port "$P0"
|
||||
HOME="$D/home" ./splinter --no-config --endpoint \
|
||||
"http://127.0.0.1:$P0/v1/chat/completions" --model m \
|
||||
--a2a-server-listen 127.0.0.1 --a2a-listen-port "$P1" \
|
||||
>"$D/out" 2>"$D/err" &
|
||||
F1=$!
|
||||
check wait_port "$P1"
|
||||
|
||||
r=$(send "ctx-multi" "eins")
|
||||
check test "$(answer "$r")" = "users=1"
|
||||
r=$(send "ctx-multi" "zwei")
|
||||
check test "$(answer "$r")" = "users=2"
|
||||
r=$(send "ctx-other" "eins")
|
||||
check test "$(answer "$r")" = "users=1"
|
||||
|
||||
# no contextId: the server makes one and returns it
|
||||
r=$(send "" "eins")
|
||||
check test "$(answer "$r")" = "users=1"
|
||||
ctx=$(context_of "$r")
|
||||
check test -n "$ctx"
|
||||
r=$(send "$ctx" "zwei")
|
||||
check test "$(answer "$r")" = "users=2"
|
||||
|
||||
if [ "$fails" -eq 0 ]; then echo "test_a2a_context: ok"; exit 0; fi
|
||||
exit 1
|
||||
+6
-6
@@ -456,8 +456,8 @@ sich selbst hin:</p>
|
||||
splinter: A2A server on 127.0.0.1:8099 (token required)</pre>
|
||||
<p><code>POST /a2a</code> nimmt <code>SendMessage</code>, <code>SendStreamingMessage</code>
|
||||
(SSE), <code>GetTask</code> und <code>ListTasks</code> als JSON-RPC; die Agent Card liegt unter
|
||||
<code>/.well-known/agent-card.json</code>. Ein Turn pro Anfrage, eigene
|
||||
Konversation. Jenseits von Loopback ist der Bearer-Token Pflicht.</p>""",
|
||||
<code>/.well-known/agent-card.json</code>. Ein <code>contextId</code> ist eine
|
||||
Konversation; ohne eines legt der Server eins an und gibt es zurueck. Jenseits von Loopback ist der Bearer-Token Pflicht.</p>""",
|
||||
]
|
||||
|
||||
SECTIONS["en"] += [
|
||||
@@ -502,8 +502,8 @@ itself:</p>
|
||||
splinter: A2A server on 127.0.0.1:8099 (token required)</pre>
|
||||
<p><code>POST /a2a</code> takes <code>SendMessage</code>, <code>SendStreamingMessage</code>
|
||||
(SSE), <code>GetTask</code> and <code>ListTasks</code> as JSON-RPC; the agent card lives at
|
||||
<code>/.well-known/agent-card.json</code>. One turn per request, its own
|
||||
conversation. Beyond loopback the bearer token is required.</p>""",
|
||||
<code>/.well-known/agent-card.json</code>. A <code>contextId</code> is a
|
||||
conversation; without one the server makes one and returns it. Beyond loopback the bearer token is required.</p>""",
|
||||
]
|
||||
|
||||
|
||||
@@ -592,8 +592,8 @@ si mesmo:</p>
|
||||
splinter: A2A server on 127.0.0.1:8099 (token required)</pre>
|
||||
<p><code>POST /a2a</code> aceita <code>SendMessage</code>, <code>SendStreamingMessage</code>
|
||||
(SSE), <code>GetTask</code> e <code>ListTasks</code> em JSON-RPC; o agent card fica em
|
||||
<code>/.well-known/agent-card.json</code>. Um turno por requisicao, conversa
|
||||
propria. Fora do loopback o token Bearer e obrigatorio.</p>""",
|
||||
<code>/.well-known/agent-card.json</code>. Um <code>contextId</code> e uma conversa;
|
||||
sem ele o servidor cria um e devolve. Fora do loopback o token Bearer e obrigatorio.</p>""",
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user