|
2 | 2 |
|
3 | 3 | A strongly-typed Dart implementation of the AG-UI protocol for standardizing agent-user interactions through event-based communication. |
4 | 4 |
|
| 5 | +[](https://github.com/mattsp1290/ag-ui) |
| 6 | +[](https://dart.dev) |
| 7 | +[](https://github.com/mattsp1290/ag-ui/blob/main/docs/specification.md) |
| 8 | + |
5 | 9 | ## Features |
6 | 10 |
|
7 | 11 | ### ✅ Implemented |
@@ -54,8 +58,7 @@ Then run: |
54 | 58 | dart pub get |
55 | 59 | ``` |
56 | 60 |
|
57 | | -## Quickstart |
58 | | -### Basic Usage |
| 61 | +## Quick Start |
59 | 62 |
|
60 | 63 | ```dart |
61 | 64 | import 'package:ag_ui/ag_ui.dart'; |
@@ -99,9 +102,9 @@ void main() async { |
99 | 102 | } |
100 | 103 | ``` |
101 | 104 |
|
102 | | -## Usage Examples |
| 105 | +## Usage |
103 | 106 |
|
104 | | -### 1. Initialize Client |
| 107 | +### Initialize Client |
105 | 108 |
|
106 | 109 | ```dart |
107 | 110 | import 'package:ag_ui/ag_ui.dart'; |
@@ -136,7 +139,7 @@ final customClient = AgUiClient( |
136 | 139 | ); |
137 | 140 | ``` |
138 | 141 |
|
139 | | -### 2. Send User Message and Stream Response |
| 142 | +### Send User Message and Stream Response |
140 | 143 |
|
141 | 144 | ```dart |
142 | 145 | import 'dart:io'; |
@@ -182,7 +185,7 @@ Future<void> sendMessage(String userInput) async { |
182 | 185 | } |
183 | 186 | ``` |
184 | 187 |
|
185 | | -### 3. Handle Tool Calls |
| 188 | +### Handle Tool Calls |
186 | 189 |
|
187 | 190 | ```dart |
188 | 191 | import 'package:ag_ui/ag_ui.dart'; |
@@ -264,7 +267,7 @@ String processToolCall(ToolCall toolCall) { |
264 | 267 | } |
265 | 268 | ``` |
266 | 269 |
|
267 | | -### 4. Manage Conversation State |
| 270 | +### Manage Conversation State |
268 | 271 |
|
269 | 272 | ```dart |
270 | 273 | import 'dart:io'; |
@@ -342,7 +345,7 @@ class ConversationManager { |
342 | 345 | } |
343 | 346 | ``` |
344 | 347 |
|
345 | | -### 5. Error Handling and Cancellation |
| 348 | +### Error Handling and Cancellation |
346 | 349 |
|
347 | 350 | ```dart |
348 | 351 | import 'dart:async'; |
@@ -413,7 +416,7 @@ bool shouldCancel(BaseEvent event) { |
413 | 416 | } |
414 | 417 | ``` |
415 | 418 |
|
416 | | -### 6. Custom Event Processing |
| 419 | +### Custom Event Processing |
417 | 420 |
|
418 | 421 | ```dart |
419 | 422 | import 'dart:io'; |
@@ -485,7 +488,7 @@ void main() async { |
485 | 488 | } |
486 | 489 | ``` |
487 | 490 |
|
488 | | -### 7. Using Environment Variables |
| 491 | +### Using Environment Variables |
489 | 492 |
|
490 | 493 | ```dart |
491 | 494 | import 'dart:io'; |
@@ -515,7 +518,7 @@ AgUiClient createClientFromEnv() { |
515 | 518 | // AGUI_BASE_URL=https://api.example.com AGUI_API_KEY=sk-xxx dart run main.dart |
516 | 519 | ``` |
517 | 520 |
|
518 | | -### 8. Complete End-to-End Example |
| 521 | +### Complete End-to-End Example |
519 | 522 |
|
520 | 523 | ```dart |
521 | 524 | import 'dart:io'; |
@@ -649,92 +652,6 @@ Future<void> main() async { |
649 | 652 | } |
650 | 653 | ``` |
651 | 654 |
|
652 | | -### Handling Tool Calls |
653 | | - |
654 | | -```dart |
655 | | -import 'package:ag_ui/ag_ui.dart'; |
656 | | -import 'dart:convert'; |
657 | | -
|
658 | | -Future<void> handleToolCalls() async { |
659 | | - final client = AgUiClient( |
660 | | - config: AgUiConfig(baseUrl: 'http://localhost:20203'), |
661 | | - ); |
662 | | -
|
663 | | - final messages = <Message>[]; |
664 | | - |
665 | | - // Initial user message |
666 | | - messages.add(UserMessage( |
667 | | - id: 'msg_1', |
668 | | - content: 'What\'s the weather in San Francisco?', |
669 | | - )); |
670 | | -
|
671 | | - final input = RunAgentInput( |
672 | | - threadId: 'thread_${DateTime.now().millisecondsSinceEpoch}', |
673 | | - runId: 'run_${DateTime.now().millisecondsSinceEpoch}', |
674 | | - messages: messages, |
675 | | - state: {}, |
676 | | - tools: [], |
677 | | - context: [], |
678 | | - forwardedProps: {}, |
679 | | - ); |
680 | | -
|
681 | | - await for (final event in client.streamEvents('/agent', input)) { |
682 | | - if (event is MessagesSnapshotEvent) { |
683 | | - // Check for tool calls in assistant messages |
684 | | - for (final message in event.messages) { |
685 | | - if (message is AssistantMessage && message.toolCalls != null) { |
686 | | - for (final toolCall in message.toolCalls!) { |
687 | | - print('Tool called: ${toolCall.function.name}'); |
688 | | - print('Arguments: ${toolCall.function.arguments}'); |
689 | | - |
690 | | - // Provide tool result |
691 | | - final toolResult = ToolMessage( |
692 | | - id: 'tool_msg_${DateTime.now().millisecondsSinceEpoch}', |
693 | | - content: json.encode({'temperature': 72, 'condition': 'sunny'}), |
694 | | - toolCallId: toolCall.id, |
695 | | - ); |
696 | | - |
697 | | - messages.add(toolResult); |
698 | | - |
699 | | - // Continue conversation with tool result |
700 | | - final continuedInput = RunAgentInput( |
701 | | - threadId: input.threadId, |
702 | | - runId: 'run_${DateTime.now().millisecondsSinceEpoch}', |
703 | | - messages: messages, |
704 | | - state: {}, |
705 | | - tools: [], |
706 | | - context: [], |
707 | | - forwardedProps: {}, |
708 | | - ); |
709 | | - |
710 | | - // Stream the continuation |
711 | | - await for (final nextEvent in client.streamEvents('/agent', continuedInput)) { |
712 | | - // Handle continuation events... |
713 | | - if (nextEvent is RunFinishedEvent) break; |
714 | | - } |
715 | | - } |
716 | | - } |
717 | | - } |
718 | | - } |
719 | | - } |
720 | | -} |
721 | | -``` |
722 | | - |
723 | | -### Environment Variables |
724 | | - |
725 | | -Configure the client using environment variables: |
726 | | - |
727 | | -```bash |
728 | | -export AGUI_BASE_URL=http://your-server:20203 |
729 | | -export AGUI_API_KEY=your-api-key-here |
730 | | - |
731 | | -dart run your_app.dart |
732 | | -``` |
733 | | - |
734 | | -```dart |
735 | | -// Client will automatically use environment variables |
736 | | -final client = AgUiClient.fromEnvironment(); |
737 | | -``` |
738 | 655 |
|
739 | 656 | ## API Overview |
740 | 657 |
|
@@ -807,7 +724,7 @@ dart pub get |
807 | 724 | dart run ag_ui_example --help |
808 | 725 | ``` |
809 | 726 |
|
810 | | -## Integration Testing |
| 727 | +## Testing |
811 | 728 |
|
812 | 729 | The SDK includes comprehensive integration tests that validate compatibility with AG-UI servers. To run tests locally: |
813 | 730 |
|
@@ -881,9 +798,6 @@ Contributions are welcome! Please: |
881 | 798 |
|
882 | 799 | This SDK is part of the AG-UI Protocol project. See the [main repository](https://github.com/mattsp1290/ag-ui) for license information. |
883 | 800 |
|
884 | | -## Versioning |
885 | | - |
886 | | -This SDK follows semantic versioning. Version history will be tracked in future releases. |
887 | 801 |
|
888 | 802 | ## Support |
889 | 803 |
|
|
0 commit comments