|
| 1 | +# Generative AI plugin for Backstage (Experimental) |
| 2 | + |
| 3 | +This experimental Backstage plugin helps build generative AI assistants in a manner that can leverage the broader Backstage plugin ecosystem. It relies on "tool use" to provide LLMs with access to existing Backstage backend plugins so that the models can access data via Backstage such as the catalog, TechDocs, CI/CD, Kubernetes resources etc. |
| 4 | + |
| 5 | +Features: |
| 6 | + |
| 7 | +- Simple conversational chat interface |
| 8 | +- Configure multiple AI "agents" for specific purposes |
| 9 | +- Modular approach to providing agent implementations |
| 10 | +- Provide "tools" to agents through Backstage extensions |
| 11 | + |
| 12 | +## Before you begin |
| 13 | + |
| 14 | +Considerations before you explore this plugin: |
| 15 | + |
| 16 | +1. Its experimental |
| 17 | +1. Using this plugin will incur costs from your LLM provider, you are responsible for these |
| 18 | +1. This plugin does not build in guardrails or other protective mechanisms against prompt injection, leaking of sensitive information etc. and you are responsible for these |
| 19 | + |
| 20 | +## Pre-requisites |
| 21 | + |
| 22 | +This plugin relies on external LLMs, and will generally require models that support tool-use/function-calling. Some examples of models that support this include: |
| 23 | + |
| 24 | +1. Anthropic Claude >= 3 (Haiku, Sonnet, Opus) |
| 25 | +1. OpenAI |
| 26 | +1. Meta Llama (certain models) |
| 27 | + |
| 28 | +The example LangGraph implementation provided can use: |
| 29 | + |
| 30 | +1. [Amazon Bedrock](https://aws.amazon.com/bedrock/) |
| 31 | +1. [OpenAI](https://openai.com/) |
| 32 | + |
| 33 | +To explore support for other models/providers please raise a GitHub issue. |
| 34 | + |
| 35 | +## Installation |
| 36 | + |
| 37 | +NOTE: This guide will use the provided LangGraph implementation. To implement your own agent type see [Extending](#extending). |
| 38 | + |
| 39 | +This guide assumes that you are familiar with the general [Getting Started](../../docs/getting-started.md) documentation and have assumes you have an existing Backstage application. |
| 40 | + |
| 41 | +### Backend package |
| 42 | + |
| 43 | +Install the backend package in your Backstage app: |
| 44 | + |
| 45 | +```shell |
| 46 | +yarn workspace backend add @aws/genai-plugin-for-backstage-backend @aws/genai-plugin-langgraph-agent-for-backstage |
| 47 | +``` |
| 48 | + |
| 49 | +Add the plugin to the `packages/backend/src/index.ts`: |
| 50 | + |
| 51 | +```typescript |
| 52 | +const backend = createBackend(); |
| 53 | +// ... |
| 54 | +backend.add(import('@aws/genai-plugin-for-backstage-backend')); |
| 55 | +backend.add(import('@aws/genai-plugin-langgraph-agent-for-backstage')); |
| 56 | +// ... |
| 57 | +backend.start(); |
| 58 | +``` |
| 59 | + |
| 60 | +Verify that the backend plugin is running in your Backstage app. You should receive `{"status":"ok"}` when accessing this URL: |
| 61 | + |
| 62 | +`http://<your backstage app>/api/aws-genai/health`. |
| 63 | + |
| 64 | +### Frontend package |
| 65 | + |
| 66 | +Install the frontend package in your Backstage app: |
| 67 | + |
| 68 | +```shell |
| 69 | +yarn workspace app add @aws/genai-plugin-for-backstage |
| 70 | +``` |
| 71 | + |
| 72 | +Edit `packages/app/src/App.tsx` to add a route for the chat UI page: |
| 73 | + |
| 74 | +```typescript |
| 75 | +import { AgentChatPage } from '@aws/genai-plugin-for-backstage'; |
| 76 | + |
| 77 | +{ |
| 78 | + /* ... */ |
| 79 | +} |
| 80 | + |
| 81 | +const routes = ( |
| 82 | + <FlatRoutes> |
| 83 | + /* ... */ |
| 84 | + <Route path="/assistant/:agentName" element={<AgentChatPage />} /> |
| 85 | + </FlatRoutes> |
| 86 | +); |
| 87 | +``` |
| 88 | + |
| 89 | +Now edit `packages/app/src/components/Root/Root.tsx` to add a menu item: |
| 90 | + |
| 91 | +```tsx |
| 92 | +import { ChatIcon } from '@backstage/core-components'; |
| 93 | + |
| 94 | +{ |
| 95 | + /* ... */ |
| 96 | +} |
| 97 | +export const Root = ({ children }: PropsWithChildren<{}>) => ( |
| 98 | + <SidebarPage> |
| 99 | + <Sidebar> |
| 100 | + {/* ... */} |
| 101 | + <SidebarGroup label="Menu" icon={<MenuIcon />}> |
| 102 | + {/* ... */} |
| 103 | + <SidebarItem |
| 104 | + icon={ChatIcon} |
| 105 | + to="assistant/general" |
| 106 | + text="Chat Assistant" |
| 107 | + /> |
| 108 | + {/* ... */} |
| 109 | + </SidebarGroup> |
| 110 | + {/* ... */} |
| 111 | + </Sidebar> |
| 112 | + {/* ... */} |
| 113 | + </SidebarPage> |
| 114 | +); |
| 115 | +``` |
| 116 | + |
| 117 | +The URL `assistant/general` means we're going to be using an agent named `general`, which we'll configure below. |
| 118 | + |
| 119 | +### Creating your first agent |
| 120 | + |
| 121 | +This plugin is built around the notion of creating one or more "agents" that can be invoked. These are defined by configuration, so lets configure our first agent. |
| 122 | + |
| 123 | +Add this to your Backstage configuration file (for example `app-config.yaml`): |
| 124 | + |
| 125 | +```yaml |
| 126 | +genai: |
| 127 | + agents: |
| 128 | + general: # This matches the URL in the frontend |
| 129 | + description: General chat assistant |
| 130 | + prompt: > |
| 131 | + You are an expert in platform engineering and answer questions in a succinct and easy to understand manner. |
| 132 | +
|
| 133 | + Answers should always be well-structured and use well-formed Markdown. |
| 134 | +
|
| 135 | + The current user is {username} and you can provide that information if asked. |
| 136 | + langgraph: |
| 137 | + messagesMaxTokens: 150000 # Set based on context of chosen model, prune message history based on number of tokens |
| 138 | + # Use appropriate snippet for your model provider |
| 139 | + bedrock: |
| 140 | + modelId: 'anthropic.claude-3-5-sonnet-20241022-v2:0' |
| 141 | + region: us-west-2 |
| 142 | + # openai: |
| 143 | + # apiKey: ${OPENAI_API_KEY} |
| 144 | +``` |
| 145 | + |
| 146 | +See the [LangGraph agent documentation](./agent-langgraph/) for the full configuration reference. |
| 147 | + |
| 148 | +Start the Backstage application: |
| 149 | + |
| 150 | +``` |
| 151 | +yarn dev |
| 152 | +``` |
| 153 | + |
| 154 | +Access the application in your browser and select the "Chat Assistant" option in the menu. Ask a general question like "What is Terraform?". |
| 155 | + |
| 156 | +### Adding tools |
| 157 | + |
| 158 | +We can provide tools/functions that can be called by agents to retrieve context or perform actions. Tools can be added to the agent using a Backstage extension point and packaged as NPM packages. |
| 159 | + |
| 160 | +There are several tools built in to the plugin related to core Backstage functionality. The `backstageCatalogSearch`, `backstageEntity` and `backstageTechdocsSearch` tools to give the model basic access to the Backstage catalog and TechDocs documentation. |
| 161 | + |
| 162 | +Update the previous agent definition to add the `tools` field: |
| 163 | + |
| 164 | +```yaml |
| 165 | +genai: |
| 166 | + agents: |
| 167 | + general: |
| 168 | + description: [...] |
| 169 | + prompt: [...] |
| 170 | + langgraph: [...] |
| 171 | + tool: |
| 172 | + - backstageCatalogSearch |
| 173 | + - backstageEntity |
| 174 | + - backstageTechdocsSearch |
| 175 | +``` |
| 176 | +
|
| 177 | +Restart Backstage to reload the configuration and try asking the chat assistant a question related to information in the your Backstage catalog, for example "Summarize <component name> from the Backstage catalog". |
| 178 | +
|
| 179 | +NOTE: After Backstage starts locally there can be a delay indexing the catalog and TechDocs for search. You will not receive search results until the index is built. |
| 180 | +
|
| 181 | +## Further reading |
| 182 | +
|
| 183 | +You can view the rest of the documentation to understand how to evolve your chat assistant |
| 184 | +
|
| 185 | +1. Prompting tips: Various tips on how to configure the agent system prompt. [See here](./docs/prompting-tips.md). |
| 186 | +1. Tools: Provide tools/functions that can be called by agents to retrieve context or perform actions. [See here](./docs/tools.md). |
| 187 | +1. Agent implementation: Provide an implementation for how an agent responds to prompts. [See here](./docs/agent-types.md). |
0 commit comments