http_server
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| AcpHttpServer aclientp.http_server ASGI app serving ACP over Streamable HTTP and WebSocket on one endpoint. |
🛈 DocStrings¶
Server side of ACP's Streamable HTTP & WebSocket transport (experimental).
Implements the server of the "Streamable HTTP & WebSocket Transport" RFD
(docs/rfds/streamable-http-websocket-transport.mdx in the ACP repository), routing
like the TypeScript SDK's AcpServer (@agentclientprotocol/sdk/experimental), on
one endpoint:
POSTsends a client message.initialize(withoutAcp-Connection-Id) creates a connection and is answered directly (200,Acp-Connection-Idheader); everything else is answered202and its response is delivered on an SSE stream.GETopens an SSE stream: the connection's (Acp-Connection-Id) or a session's (plusAcp-Session-Id).GETwithUpgrade: websocketopens a WebSocket instead, carrying one JSON-RPC message per text frame.DELETEends the connection.
Routing: a response goes where its request came from (the session named by the request,
or the connection), except session/load, which is answered on the connection stream.
Agent requests and notifications naming a session go to that session's stream, others to
the connection's; the client's answers to agent requests must name the same session.
One deviation from the RFD: messages for a session the client cannot know yet (no
response, client message or stream has named it) go to the connection stream. Otherwise
an agent request made while handling session/new (e.g. running a command in a client
terminal) would wait for a session stream the client can only open after that response,
and the two would deadlock. Clients accept messages on either stream.
Streams buffer until a receiver attaches and allow one receiver at a time (409). Missed
messages are not replayed (ACP v1).
Backpressure (like the TypeScript SDK): once a connection holds max_buffered_bytes of
output its client has not taken, the agent's writes wait; a client that takes nothing for
max_output_stall seconds meanwhile is dropped (HTTP and WebSocket alike).
Each connection runs its own agent connection, like the WebSocket transport.
DEFAULT_MAX_BUFFERED_BYTES
module-attribute
¶
Output a connection may hold for its client before the agent has to wait.
DEFAULT_MAX_OUTPUT_STALL_SECONDS
module-attribute
¶
How long a client may take nothing while over the limit before the connection closes.
SESSION_SCOPED_METHODS
module-attribute
¶
SESSION_SCOPED_METHODS = frozenset({
"session/cancel",
"session/close",
"session/delete",
"session/fork",
"session/load",
"session/prompt",
"session/resume",
"session/set_config_option",
"session/set_mode",
"session/set_model",
})
Client methods whose POST must carry Acp-Session-Id.
Authenticate
¶
Identifies the caller (None: rejected with 401). Connections belong to their creator.
ServeConnection
¶
Serves one ACP connection over newline-delimited JSON byte streams until EOF.
AcpHttpServer
dataclass
¶
ASGI app serving ACP over Streamable HTTP and WebSocket on one endpoint.
Source code in src/aclientp/http_server.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | |
allow_origins
class-attribute
instance-attribute
¶
CORS origins for browser clients.
authenticate
class-attribute
instance-attribute
¶
authenticate: Authenticate | None = None
Caller identification; None accepts everyone (local use only).
max_buffered_bytes
class-attribute
instance-attribute
¶
max_buffered_bytes: int = DEFAULT_MAX_BUFFERED_BYTES
Output a connection may hold for its client before the agent has to wait.
max_output_stall
class-attribute
instance-attribute
¶
max_output_stall: float = DEFAULT_MAX_OUTPUT_STALL_SECONDS
Seconds a client may take nothing while over the limit before it is dropped.
serve_connection
instance-attribute
¶
serve_connection: ServeConnection
Runs the agent for one connection.
app
¶
The Starlette application.
Source code in src/aclientp/http_server.py
bearer_token_auth
¶
bearer_token_auth(token: str) -> Authenticate
Authenticate with Authorization: Bearer <token>.