Skip to content

Commit cf19564

Browse files
authored
feat: Add Generative AI plugin (#313)
1 parent 66ffd3b commit cf19564

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+7411
-227
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ For detailed documentation regarding each plugin please see below:
1515
| AWS CodePipeline | [Link](./plugins/codepipeline/README.md) | Show the status of AWS CodePipeline pipelines on the entity page. |
1616
| AWS CodeBuild | [Link](./plugins/codebuild/README.md) | Show the status of AWS CodeBuild projects on the entity page. |
1717
| AWS Config catalog module | [Link](./plugins/core/catalog-config/README.md) | Module that implements an entity provider to ingest AWS resources in to the Backstage catalog. |
18+
| Generative AI | [Link](./plugins/genai/README.md) | Build assistants powered by Generative AI |
1819
| Cost Insights for AWS | [Link](./plugins/cost-insights/README.md) | An implementation of the Cost Insights plugin that provides AWS cost information |
1920

2021
## Security

packages/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@aws/aws-codebuild-plugin-for-backstage": "workspace:^",
1919
"@aws/aws-codepipeline-plugin-for-backstage": "workspace:^",
2020
"@aws/cost-insights-plugin-for-backstage": "workspace:^",
21+
"@aws/genai-plugin-for-backstage": "workspace:^",
2122
"@backstage-community/plugin-cost-insights": "^0.12.25",
2223
"@backstage-community/plugin-github-actions": "^0.6.16",
2324
"@backstage-community/plugin-tech-radar": "^0.7.4",

packages/app/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { RequirePermission } from '@backstage/plugin-permission-react';
3939
import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/alpha';
4040
import { CostInsightsPage } from '@backstage-community/plugin-cost-insights';
4141
import { costInsightsAwsPlugin } from '@aws/cost-insights-plugin-for-backstage';
42+
import { AgentChatPage } from '@aws/genai-plugin-for-backstage';
4243

4344
const app = createApp({
4445
apis,
@@ -113,6 +114,7 @@ const routes = (
113114
<Route path="/settings" element={<UserSettingsPage />} />
114115
<Route path="/catalog-graph" element={<CatalogGraphPage />} />
115116
<Route path="/cost-insights" element={<CostInsightsPage />} />
117+
<Route path="/assistant/:agentName" element={<AgentChatPage />} />
116118
</FlatRoutes>
117119
);
118120

packages/app/src/components/Root/Root.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
SidebarSpace,
2424
useSidebarOpenState,
2525
Link,
26+
ChatIcon,
2627
} from '@backstage/core-components';
2728
import MenuIcon from '@material-ui/icons/Menu';
2829
import SearchIcon from '@material-ui/icons/Search';
@@ -70,6 +71,11 @@ export const Root = ({ children }: PropsWithChildren<{}>) => (
7071
<SidebarItem icon={ExtensionIcon} to="api-docs" text="APIs" />
7172
<SidebarItem icon={LibraryBooks} to="docs" text="Docs" />
7273
<SidebarItem icon={CreateComponentIcon} to="create" text="Create..." />
74+
<SidebarItem
75+
icon={ChatIcon}
76+
to="assistant/general"
77+
text="Chat Assistant"
78+
/>
7379
{/* End global nav */}
7480
<SidebarDivider />
7581
<SidebarScrollWrapper>

packages/backend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"@aws/aws-codepipeline-plugin-for-backstage-backend": "workspace:^",
2222
"@aws/aws-core-plugin-for-backstage-scaffolder-actions": "workspace:^",
2323
"@aws/cost-insights-plugin-for-backstage-backend": "workspace:^",
24+
"@aws/genai-plugin-for-backstage-backend": "workspace:^",
25+
"@aws/genai-plugin-langgraph-agent-for-backstage": "workspace:^",
2426
"@backstage/backend-defaults": "^0.5.3",
2527
"@backstage/backend-plugin-api": "^1.0.2",
2628
"@backstage/catalog-client": "^1.8.0",

packages/backend/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ backend.add(import('@aws/aws-core-plugin-for-backstage-scaffolder-actions'));
2020

2121
backend.add(import('@aws/cost-insights-plugin-for-backstage-backend'));
2222

23+
backend.add(import('@aws/genai-plugin-for-backstage-backend'));
24+
backend.add(import('@aws/genai-plugin-langgraph-agent-for-backstage'));
25+
2326
backend.start();

plugins/genai/README.md

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Generative AI plugin for Backstage - LangGraph Agent Type
2+
3+
This package implements an agent for the Generative AI plugin for Backstage based on [LangGraph.js](https://github.com/langchain-ai/langgraphjs).
4+
5+
Features:
6+
7+
1. [ReAct pattern](https://react-lm.github.io/) to use available tools to answer prompts
8+
1. Choose between Amazon Bedrock or OpenAI as the model provider
9+
1. Integrate with [LangFuse](https://github.com/langfuse/langfuse) for observability
10+
11+
Limitations:
12+
13+
1. In-memory persistence only: Chat sessions only persist in-memory
14+
15+
## Configuration
16+
17+
This agent can be configured at two different levels, global and per-agent
18+
19+
### Global
20+
21+
Global configuration values apply to all agents, all of this is optional:
22+
23+
```yaml
24+
genai:
25+
langgraph:
26+
langfuse: # (Optional) Configuration for LangFuse observability
27+
baseUrl: http://localhost:3001 # (Required) LangFuse URL
28+
publicKey: pk-aaa # (Required) Public key
29+
secretKey: sk-bbb # (Required) Secret key
30+
```
31+
32+
### Per-agent
33+
34+
Per-agent configuration only applies to the agent for which it corresponds. The available parameters are:
35+
36+
```yaml
37+
genai:
38+
agents:
39+
general:
40+
description: [...]
41+
prompt: [...]
42+
langgraph:
43+
messagesMaxTokens: 100000 # (Required) Prune message history to maximum of this number of tokens
44+
temperature: 0 # (Optional) Model temperature
45+
maxTokens: 4000 # (Optional) Maximum output tokens
46+
topP: 0.9 # (Optional) Model topP
47+
# Only include the subsequent section for your model provider
48+
# Bedrock only
49+
bedrock:
50+
modelId: 'anthropic.claude-3-5-sonnet-20241022-v2:0' # (Required) Bedrock model ID
51+
region: us-west-2 # (Required) Bedrock AWS region
52+
# OpenAI only
53+
openai:
54+
apiKey: ${OPENAI_API_KEY} # (Required) OpenAI model name
55+
modelName: 'gpt-3.5-turbo-instruct' # (Optional) OpenAI model name
56+
```
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* Licensed under the Apache License, Version 2.0 (the "License").
4+
* You may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
14+
export interface Config {
15+
genai?: {
16+
agents?: {
17+
[name: string]: {
18+
langgraph?: {
19+
/**
20+
* (Required) Maximum tokens to retain in context sent to the model
21+
*/
22+
messagesMaxTokens: number;
23+
/**
24+
* (Optional) Maximum tokens that will be returned by the model
25+
*/
26+
maxTokens?: number;
27+
/**
28+
* (Optional) Model temperature
29+
*/
30+
temperature?: number;
31+
/**
32+
* (Optional) Model topP
33+
*/
34+
topP?: number;
35+
/**
36+
* (Optional) Specific configuration for Amazon Bedrock
37+
*/
38+
bedrock?: {
39+
/**
40+
* (Required) Region to use to access Amazon Bedrock API
41+
*/
42+
region: string;
43+
/**
44+
* (Required) Amazon Bedrock model ID to use
45+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html
46+
*/
47+
modelId: string;
48+
};
49+
/**
50+
* (Optional) Specific configuration for OpenAI
51+
*/
52+
openai?: {
53+
/**
54+
* (Required) OpenAI API key for authentication
55+
* @visibility secret
56+
*/
57+
apiKey: string;
58+
/**
59+
* (Optional) Name of the OpenAI model to use
60+
*/
61+
modelName?: string;
62+
};
63+
};
64+
};
65+
};
66+
};
67+
}

0 commit comments

Comments
 (0)