pi 0.1.0 copy "pi: ^0.1.0" to clipboard
pi: ^0.1.0 copied to clipboard

A Dart agent framework for building AI-powered applications with tool execution, streaming events, and session persistence.

example/main.dart

/// Example demonstrating pi_agent usage.
///
/// Run with: dart run example/main.dart
library;

import 'dart:io';

import 'package:pi/pi.dart';

void main() async {
  final apiKey = Platform.environment['OPENAI_API_KEY'];
  if (apiKey == null) {
    stderr.writeln('Set OPENAI_API_KEY environment variable.');
    exit(1);
  }

  final agent = Agent(
    model: const Model(
      provider: 'openai',
      modelId: 'gpt-4o',
      contextWindow: 128000,
    ),
    systemPrompt: 'You are a helpful assistant. Be concise.',
    getApiKey: (provider) async => apiKey,
  );

  agent.subscribe((event) {
    switch (event) {
      case MessageUpdate(message: final msg):
        if (msg is AssistantMessage) {
          for (final block in msg.content) {
            if (block is TextBlock) stdout.write(block.text);
          }
        }
      case AgentEnd():
        print('\n');
      default:
        break;
    }
  });

  await agent.prompt('What is the capital of France?');

  // Continue the conversation
  await agent.continue_();
}
0
likes
140
points
13
downloads

Documentation

API reference

Publisher

verified publisherzuzu.dev

Weekly Downloads

A Dart agent framework for building AI-powered applications with tool execution, streaming events, and session persistence.

Repository (GitHub)

Topics

#ai #agent #llm #chatbot

License

BSD-3-Clause (license)

Dependencies

http, yaml

More

Packages that depend on pi