Documentation
DocumentationQuickstart

Quickstart

In this quickstart guide, we'll walk through the process of creating a Dash Agent that indexes the official Flutter docs and allows users to ask questions based on the indexed content.

We'll use the Dash Agent framework available as dash_agent on pub.dev

Prerequisites

  • Dart SDK installed
  • Basic knowledge of Dart programming language

Create a New Project

First, let's create a new Dash Agent project using the dash_cli tool.

  1. Activate the dash_cli globally:

    dart pub global activate dash_cli
    
  2. Create a new Dash Agent project:

    dash_cli create flutter
    

This will setup a starter agent project tempalte for us to edit further.

Configure the Agent

Open the newly created project in your preferred IDE or text editor.

  1. Open the lib folder.

  2. In the lib/data_sources.dart, add the DocsDataSource class:

     class DocsDataSource extends DataSource {
       @override
       List<FileDataObject> get fileObjects => [];
     
       @override
       List<ProjectDataObject> get projectObjects => [];
     
       @override
       List<WebDataObject> get webObjects => [
             WebDataObject.fromSiteMap('https://docs.flutter.dev/sitemap.xml'),
             WebDataObject.fromSiteMap('https://dart.dev/sitemap.xml')
           ];
     }

    This data source indexes the Flutter docs using the sitemap of the website.

  3. In lib/agent.dart, update the AgentConfiguration to register the necessary data sources and commands:

    class MyAgent extends AgentConfiguration {
      final docsSource = DocsDataSource();
     
      @override
      List<DataSource> get registeredDataSources => [docsSource];
     
      @override
      List<Command> get registerSupportedCommands => [AskCommand(docsSource: docsSource)];
    }
  4. Create a new file lib/commands/ask.dart and define the AskCommand class:

    class AskCommand extends Command {
      AskCommand({required this.docsSource});
     
      final DataSource docsSource;
     
      final userQuery = StringInput('Your query');
     
      @override
      String get slug => '/ask';
     
      @override
      String get intent => 'Ask about Flutter';
     
      @override
      List<DashInput> get registerInputs => [userQuery];
     
      @override
      List<Step> get steps {
        final matchingDocuments = MatchDocumentObject();
        final queryOutput = QueryOutput();
     
        return [
          MatchingDocumentStep(
            query: '$userQuery',
            dataSources: [docsSource],
            output: matchingDocuments,
          ),
          PromptQueryStep(
            prompt: '''
              You are a Flutter documentation assistant. Answer the user's query based on the provided document references.
     
              User Query: $userQuery
     
              Document References: $matchingDocuments
            ''',
            postProcessKind: PostProcessKind.raw,
            output: queryOutput,
          ),
          AppendToChatStep(value: '$queryOutput'),
        ];
      }
     
      @override
      String get textFieldLayout => "Hi! Ask me anything from Flutter docs: $userQuery";
    }
  • slug - the slash command used to choose the command in the text field.
  • intent - short description that appears alongside the slug in dropdown.
  • textFieldLayout appear as below in the text field.
Rendered textFieldLayout in the Dash Panel

This command allows users to ask questions about Flutter, finds relevant documents from the indexed documentation, and provides an answer based on them.

Publish the Agent

Dash Agents can be published in the marketplace to be installed by anyone.

Before publishing the agent in live, it is recommended to first try it yourself by publish it as a test agent.

  1. Run the following command to start the agent in test mode:

    dash_cli publish --test
    
  2. Open the CommandDash client (e.g., VS Code extension) and install the flutter agent from the marketplace.

Open Marketplace with the `@` icon on the top right.
Open Marketplace with the `@` icon on the top right.
  1. Enter a question related to @flutter /ask in the text field and observe the agent's response.

  2. Once you're satisfied with the agent's functionality, you can publish it as a live agent.

    dash_cli publish
    

Now, the agent is available in the marketplace to installed by everyone.