acp_agent
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| ACPAgent llmling_agent.agent.acp_agent MessageNode that wraps an external ACP agent subprocess. |
||
| ACPAgentConfig llmling_agent.agent.acp_agent Configuration for an external ACP agent. |
|
|
| ACPClientHandler llmling_agent.agent.acp_agent Client handler that collects session updates and handles agent requests. |
|
|
| ACPSessionState llmling_agent.agent.acp_agent Tracks state of an ACP session. |
||
| ChatMessage llmling_agent.messaging.messages Common message format for all UI types. |
||
| MessageNode llmling_agent.messaging.messagenode Base class for all message processing nodes. |
||
| MessageStats llmling_agent.talk.stats Statistics for a single connection. |
||
NodeConfigllmling_agent_config.nodes Configuration for a Node of the messaging system. |
|
|
| TaskManager llmling_agent.utils.tasks Mixin for managing async tasks. |
🛈 DocStrings¶
ACP Agent - MessageNode wrapping an external ACP subprocess.
This module provides an agent implementation that communicates with external ACP (Agent Client Protocol) servers via stdio, enabling integration of any ACP-compatible agent into the llmling-agent pool.
The ACPAgent class acts as an ACP client, spawning an ACP server subprocess and communicating with it via JSON-RPC over stdio. This allows: - Integration of external ACP-compatible agents (like claude-code-acp) - Composition with native llmling agents via connections, teams, etc. - Full ACP protocol support including file operations and terminals
Example
config = ACPAgentConfig(
command="claude-code-acp",
name="claude_coder",
cwd="/path/to/project",
)
async with ACPAgent(config) as agent:
result = await agent.run("Write a hello world program")
print(result.content)
ACPAgent
¶
Bases: MessageNode[TDeps, str]
MessageNode that wraps an external ACP agent subprocess.
This allows integrating any ACP-compatible agent into the llmling-agent pool, enabling composition with native agents via connections, teams, etc.
The agent manages: - Subprocess lifecycle (spawn on enter, terminate on exit) - ACP protocol initialization and session creation - Prompt execution with session update collection - Client-side operations (filesystem, terminals, permissions)
Supports both blocking run() and streaming run_iter() execution modes.
Source code in src/llmling_agent/agent/acp_agent.py
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 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | |
__aenter__
async
¶
__aenter__() -> Self
Start subprocess and initialize ACP connection.
Source code in src/llmling_agent/agent/acp_agent.py
504 505 506 507 508 509 510 | |
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Clean up subprocess and connection.
Source code in src/llmling_agent/agent/acp_agent.py
512 513 514 515 516 517 518 519 520 | |
__init__
¶
__init__(config: ACPAgentConfig, **kwargs: Any) -> None
Initialize ACP agent wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ACPAgentConfig
|
Configuration for the ACP agent |
required |
**kwargs
|
Any
|
Additional arguments passed to MessageNode |
{}
|
Source code in src/llmling_agent/agent/acp_agent.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
get_stats
async
¶
get_stats() -> MessageStats
Get message statistics.
Source code in src/llmling_agent/agent/acp_agent.py
782 783 784 | |
run
async
¶
run(*prompts: Any, **kwargs: Any) -> ChatMessage[str]
Execute prompt against ACP agent.
Sends the prompt to the ACP server and waits for completion. Session updates (text chunks, tool calls, etc.) are collected and the final text content is returned as a ChatMessage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*prompts
|
Any
|
Prompts to send (will be joined with spaces) |
()
|
**kwargs
|
Any
|
Additional arguments (unused) |
{}
|
Returns:
| Type | Description |
|---|---|
ChatMessage[str]
|
ChatMessage containing the agent's aggregated text response |
Source code in src/llmling_agent/agent/acp_agent.py
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 | |
run_iter
async
¶
run_iter(*prompts: Any, **kwargs: Any) -> AsyncIterator[ChatMessage[str]]
Yield ChatMessage instances for text chunks during execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*prompts
|
Any
|
Prompts to send (will be joined with spaces) |
()
|
**kwargs
|
Any
|
Additional arguments (unused) |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[ChatMessage[str]]
|
ChatMessage for each text chunk from the ACP agent |
Source code in src/llmling_agent/agent/acp_agent.py
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | |
run_stream
async
¶
run_stream(*prompts: Any, **kwargs: Any) -> AsyncIterator[RichAgentStreamEvent[str]]
Stream native events as they arrive from ACP agent.
Yields the same event types as native agents, enabling uniform handling regardless of whether the agent is native or ACP-based.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*prompts
|
Any
|
Prompts to send (will be joined with spaces) |
()
|
**kwargs
|
Any
|
Additional arguments (unused) |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[RichAgentStreamEvent[str]]
|
RichAgentStreamEvent instances converted from ACP session updates |
Source code in src/llmling_agent/agent/acp_agent.py
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | |
ACPAgentConfig
¶
Bases: NodeConfig
Configuration for an external ACP agent.
Source code in src/llmling_agent/agent/acp_agent.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
allow_file_operations
class-attribute
instance-attribute
¶
allow_file_operations: bool = True
Whether to allow file read/write operations.
allow_terminal
class-attribute
instance-attribute
¶
allow_terminal: bool = True
Whether to allow terminal operations.
args
class-attribute
instance-attribute
¶
Arguments to pass to the command.
auto_grant_permissions
class-attribute
instance-attribute
¶
auto_grant_permissions: bool = True
Whether to automatically grant all permission requests.
env
class-attribute
instance-attribute
¶
env: dict[str, str] = field(default_factory=dict)
Environment variables to set.
ACPClientHandler
¶
Bases: Client
Client handler that collects session updates and handles agent requests.
This implements the full ACP Client protocol including: - Session update collection (text chunks, thoughts, tool calls) - Filesystem operations (read/write files) - Terminal operations (create, output, kill, release) - Permission request handling
The handler accumulates session updates in an ACPSessionState instance, allowing the ACPAgent to build the final response from streamed chunks.
Source code in src/llmling_agent/agent/acp_agent.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 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 | |
cleanup
async
¶
cleanup() -> None
Clean up all resources.
Source code in src/llmling_agent/agent/acp_agent.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
create_terminal
async
¶
create_terminal(params: CreateTerminalRequest) -> CreateTerminalResponse
Create a new terminal session.
Source code in src/llmling_agent/agent/acp_agent.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
ext_method
async
¶
ext_method(method: str, params: dict[str, Any]) -> dict[str, Any]
Handle extension methods.
Source code in src/llmling_agent/agent/acp_agent.py
443 444 445 446 | |
ext_notification
async
¶
ext_notification(method: str, params: dict[str, Any]) -> None
Handle extension notifications.
Source code in src/llmling_agent/agent/acp_agent.py
448 449 450 | |
kill_terminal
async
¶
kill_terminal(params: KillTerminalCommandRequest) -> KillTerminalCommandResponse | None
Kill terminal process.
Source code in src/llmling_agent/agent/acp_agent.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
read_text_file
async
¶
read_text_file(params: ReadTextFileRequest) -> ReadTextFileResponse
Read text from file.
Source code in src/llmling_agent/agent/acp_agent.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
release_terminal
async
¶
release_terminal(params: ReleaseTerminalRequest) -> ReleaseTerminalResponse | None
Release terminal resources.
Source code in src/llmling_agent/agent/acp_agent.py
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 | |
request_permission
async
¶
request_permission(params: RequestPermissionRequest) -> RequestPermissionResponse
Handle permission requests.
Source code in src/llmling_agent/agent/acp_agent.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
session_update
async
¶
session_update(params: SessionNotification[Any]) -> None
Handle session update notifications from the agent.
Source code in src/llmling_agent/agent/acp_agent.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
terminal_output
async
¶
terminal_output(params: TerminalOutputRequest) -> TerminalOutputResponse
Get output from terminal.
Source code in src/llmling_agent/agent/acp_agent.py
342 343 344 345 346 347 348 349 350 351 352 353 354 | |
wait_for_terminal_exit
async
¶
wait_for_terminal_exit(params: WaitForTerminalExitRequest) -> WaitForTerminalExitResponse
Wait for terminal process to exit.
Source code in src/llmling_agent/agent/acp_agent.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
write_text_file
async
¶
write_text_file(params: WriteTextFileRequest) -> WriteTextFileResponse
Write text to file.
Source code in src/llmling_agent/agent/acp_agent.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
ACPSessionState
dataclass
¶
Tracks state of an ACP session.
Source code in src/llmling_agent/agent/acp_agent.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
current_model_id
class-attribute
instance-attribute
¶
current_model_id: str | None = None
Current model ID from session state.
events
class-attribute
instance-attribute
¶
Queue of native events converted from ACP updates.
is_complete
class-attribute
instance-attribute
¶
is_complete: bool = False
Whether the prompt processing is complete.
stop_reason
class-attribute
instance-attribute
¶
stop_reason: str | None = None
Reason processing stopped.
text_chunks
class-attribute
instance-attribute
¶
Accumulated text chunks.
thought_chunks
class-attribute
instance-attribute
¶
Accumulated thought/reasoning chunks.
main
async
¶
main() -> None
Demo: Basic call to an ACP agent.
Usage
python -m llmling_agent.agent.acp_agent "Your prompt here" python -m llmling_agent.agent.acp_agent --claude "Your prompt here" python -m llmling_agent.agent.acp_agent --stream "Your prompt here"
Or with default prompt
python -m llmling_agent.agent.acp_agent
Source code in src/llmling_agent/agent/acp_agent.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 | |