Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 NEW: BaseAI CLI Software architecture agent #102

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/agents/software-architecture-agent/.env.baseai.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# !! SERVER SIDE ONLY !!
# Keep all your API keys secret — use only on the server side.

# TODO: ADD: Both in your production and local env files.
# Langbase API key for your User or Org account.
# How to get this API key https://langbase.com/docs/api-reference/api-keys
LANGBASE_API_KEY=

# TODO: ADD: LOCAL ONLY. Add only to local env files.
# Following keys are needed for local pipe runs. For providers you are using.
# For Langbase, please add the key to your LLM keysets.
# Read more: Langbase LLM Keysets https://langbase.com/docs/features/keysets
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
COHERE_API_KEY=
FIREWORKS_API_KEY=
GOOGLE_API_KEY=
GROQ_API_KEY=
MISTRAL_API_KEY=
PERPLEXITY_API_KEY=
TOGETHER_API_KEY=
XAI_API_KEY=
9 changes: 9 additions & 0 deletions examples/agents/software-architecture-agent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# baseai
**/.baseai/
node_modules
.env
package-lock.json
pnpm-lock.yaml
# env file
# env file
.env
81 changes: 81 additions & 0 deletions examples/agents/software-architecture-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
![Software Architecture Agent by ⌘ BaseAI][cover]

![License: MIT][mit] [![Fork on ⌘ Langbase][fork]][pipe]

## Build a Software Architecture Agent to use with draw.io app (vscode or https://app.diagrams.net/) with BaseAI framework — ⌘ Langbase

The **Software Architecture Agent** analyzes code in languages like C++, JavaScript, and Python to generate detailed UML diagrams using draw.io XML syntax. It seamlessly integrates with draw.io (https://app.diagrams.net/) and VSCode extensions, creating accurate class, sequence, and use case diagrams from your code or system requirements. The agent provides clear explanations of diagram elements and supports iterative refinements based on your feedback. By translating technical code structures into visual designs, it enhances your software architecture planning and understanding efficiently.

This AI Agent is built using the BaseAI framework. It leverages an agentic pipe that integrates over 30+ LLMs (including OpenAI, Gemini, Mistral, Llama, Gemma, etc.) and can handle any data, with context sizes of up to 10M+ tokens, supported by memory. The framework is compatible with any front-end framework (such as React, Remix, Astro, Next.js), giving you, as a developer, the freedom to tailor your AI application exactly as you envision.

## How to use

Navigate to `examples/agents/software-architecture-agent` and run the following commands:

```sh
# Navigate to baseai/examples/agents/software-architecture-agent
cd examples/agents/software-architecture-agent

# Install the dependencies
npm install
# or
pnpm install

# Make sure to copy .env.baseai.example file and
# create .env file and add all the relevant API keys in it
# NOTE: For this agent it is recommended to Antropic claude 3.5-sonnet
cp .env.baseai.example .env

# Run the local baseai dev server to test the examples (uses localhost:9000 port)
npx baseai@latest dev

# Run the agent
npx tsx index.ts

# NOTE: BaseAI pipe Logs are switched off by default, you can enable them in baseai config file baseai.config.ts under baseai directory
```

## Features

- Software Architecture Agent — Built with [BaseAI framework and agentic Pipe ⌘ ][qs].
- Composable Agents — build and compose agents with BaseAI.
- Add and Sync deployed pipe on Langbase locally npx baseai@latest add ([see the Code button][pipe]).

## Learn more

1. Check the [Learning path to build an agentic AI pipe with ⌘ BaseAI][learn]
2. Read the [source code on GitHub][gh] for this agent example
3. Go through Documentaion: [Pipe Quick Start][qs]
4. Learn more about [Memory features in ⌘ BaseAI][memory]
5. Learn more about [Tool calls support in ⌘ BaseAI][toolcalls]


> NOTE:
> This is a BaseAI project, you can deploy BaseAI pipes, memory and tool calls on Langbase.

---

## Authors

This project is created by [Langbase][lb] team members, with contributions from:

- Muhammad-Ali Danish - Software Engineer, [Langbase][lb] <br>
**_Built by ⌘ [Langbase.com][lb] — Ship hyper-personalized AI assistants with memory!_**

[lb]: https://langbase.com
[pipe]: https://langbase.com/examples/software-architecture-agent
[gh]: https://github.com/LangbaseInc/baseai/tree/main/examples/agents/software-architecture-agent
[cover]:https://raw.githubusercontent.com/LangbaseInc/docs-images/main/baseai/baseai-cover.png
[download]:https://download-directory.github.io/?url=https://github.com/LangbaseInc/baseai/tree/main/examples/software-architecture-agent
[learn]:https://baseai.dev/learn
[memory]:https://baseai.dev/docs/memory/quickstart
[toolcalls]:https://baseai.dev/docs/tools/quickstart
[deploy]:https://baseai.dev/docs/deployment/authentication
[signup]: https://langbase.fyi/io
[qs]:https://baseai.dev/docs/pipe/quickstart
[docs]:https://baseai.dev/docs
[xaa]:https://x.com/MrAhmadAwais
[xab]:https://x.com/AhmadBilalDev
[local]:http://localhost:9000
[mit]: https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge&color=%23000000
[fork]: https://img.shields.io/badge/FORK%20ON-%E2%8C%98%20Langbase-000000.svg?style=for-the-badge&logo=%E2%8C%98%20Langbase&logoColor=000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { BaseAIConfig } from 'baseai';

export const config: BaseAIConfig = {
log: {
isEnabled: false,
logSensitiveData: false,
pipe: true,
'pipe.completion': true,
'pipe.request': true,
'pipe.response': true,
tool: true,
memory: true
},
memory: {
useLocalEmbeddings: false
},
envFilePath: '.env'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { PipeI } from '@baseai/core';

const pipeSoftwareArchitectureAgent = (): PipeI => ({
// Replace with your API key https://langbase.com/docs/api-reference/api-keys
apiKey: process.env.LANGBASE_API_KEY!,
name: `software-architecture-agent`,
description: `Support Software Developers and Engineers in building, brainstorming and maintaining system and software designs. Use with only with https://app.diagrams.net/`,
status: `private`,
model: `anthropic:claude-3-5-sonnet-latest`,
stream: true,
json: false,
store: true,
moderate: true,
top_p: 0.75,
max_tokens: 4096,
temperature: 0.5,
presence_penalty: 0.5,
frequency_penalty: 0.5,
stop: [],
tool_choice: 'auto',
parallel_tool_calls: true,
messages: [
{
role: 'system',
content:
'You are a **Software Architect AI** specialized in **code analysis** and **UML diagram generation** using **draw.io XML syntax**. Your primary function is to interpret code and software/system-level requirements to create detailed UML diagrams compatible with draw.io. \n\n\n### **Capabilities:**\n\n1. **Code Comprehension:**\n - You can read, interpret, and understand code written in C, C++, JavaScript, TypeScript, Java, and Python**.\n \n2. **Requirement Analysis:**\n - You can process software and system-level requirements to identify key components, interactions, and workflows.\n \n3. **UML Expertise:**\n - You possess comprehensive knowledge of UML concepts, including class diagrams, sequence diagrams, use case diagrams, and more.\n \n4. **Draw.io XML Generation:**\n - You can generate UML diagrams in **draw.io XML syntax**, ensuring compatibility with draw.io for visualization and further editing.\n\n### **Instructions:**\n\n1. **Greeting:**\n - When a user says "Hello" or inquires about your purpose, greet them and provide a brief explanation of your capabilities in generating UML diagrams for using it with draw.io app. User can use it with either vscode draw.io extension or import the generated UML script for web app https://app.diagrams.net/ by saving the script with .drawio or .xml file extension and then import that file to view.\n \n2. **Input Handling:**\n - **Code Analysis:**\n - When presented with code, analyze its structure, classes, methods, and relationships.\n - Identify UML elements such as classes, interfaces, inheritance, associations, and multiplicities.\n \n - **Requirement Analysis:**\n - When provided with software or system-level requirements, extract key components, interactions, and workflows relevant to UML diagramming.\n\n3. **UML Diagram Generation:**\n - **Choose Diagram Type:**\n - Based on the input, determine the most appropriate UML diagram type (e.g., class diagram, sequence diagram).\n \n - **Draw.io XML Creation:**\n - Generate the UML diagram using **draw.io XML syntax**.\n - Ensure that all UML elements (classes, attributes, methods, relationships) are accurately represented.\n - Maintain clarity and readability in the XML structure for seamless import into draw.io.\n \n4. **Explanation:**\n - After generating the draw.io XML for the UML diagram, provide a brief explanation of the key elements and structure of the diagram.\n - Highlight important relationships and components derived from the code or requirements.\n \n5. **Iterative Improvement:**\n - If the user requests modifications or additions, adjust the draw.io XML accordingly.\n - Explain the changes made to the UML diagram based on user feedback.\n\n### **Response Format:**\n\n1. **Greeting** (if applicable)\n2. **Draw.io XML UML Diagram:**\n - Provide the generated draw.io XML code encapsulated within appropriate code blocks for easy copying.\n \n ```xml\n <!-- draw.io XML UML Diagram -->\n <mxfile>\n <!-- XML content here -->\n </mxfile>\n3. Brief Explanation:\n- A concise description of the UML diagram\'s key elements and their relationships.\n4. Offer for Clarification or Modification:\n- Invite the user to ask questions or request changes to the diagram.\n\nNotes:\n- If presented with pseudocode or incomplete code, generate the most accurate UML diagram possible based on the available information and clearly state any assumptions made.\n- Ensure that the generated draw.io XML adheres to draw.io\'s schema for seamless integration and visualization.\n- Maintain clarity and organization in the XML to facilitate easy debugging and editing by the user.'
},
{ name: 'json', role: 'system', content: '' },
{ name: 'safety', role: 'system', content: '' },
{
name: 'opening',
role: 'system',
content: 'Welcome to Langbase. Prompt away!'
},
{ name: 'rag', role: 'system', content: '' }
],
variables: [],
tools: [],
memory: []
});

export default pipeSoftwareArchitectureAgent;
73 changes: 73 additions & 0 deletions examples/agents/software-architecture-agent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'dotenv/config';
import {Message, Pipe} from '@baseai/core';
import inquirer from 'inquirer';
import ora from 'ora';
import chalk from 'chalk';
import pipeSoftwareArchitectureAgent from './baseai/pipes/software-architecture-agent';


const pipe = new Pipe(pipeSoftwareArchitectureAgent());

async function main() {
const initialSpinner = ora(
'Connecting to software-architecture-agent...',
).start();
// Messages array for keeping track of the conversation
const messages: Message[] = [
// Initial message to the agent
{role: 'user', content: 'Hello how can I use your services?'},
];

try {
const {completion} = await pipe.run({
messages,
});

// Add the agent response to the messages array
messages.push({role: 'assistant', content: completion});

initialSpinner.stop();
console.log(chalk.cyan('Agent response...'));
console.log(completion);
} catch (error) {
initialSpinner.stop();
console.error(chalk.red('Error processing initial request:'), error);
}

while (true) {
const {userMsg} = await inquirer.prompt([
{
type: 'input',
name: 'userMsg',
message: chalk.blue(
'Enter your query (or type "exit" to quit):',
),
},
]);

if (userMsg.toLowerCase() === 'exit') {
console.log(chalk.green('Goodbye!'));
break;
}

const spinner = ora('Processing your request...').start();
messages.push({role: 'user', content: userMsg});
try {
const {completion: swArchAgentResponse} = await pipe.run({
messages,
});
messages.push({
role: 'assistant',
content: swArchAgentResponse,
});
spinner.stop();
console.log(chalk.cyan('Agent:'));
console.log(swArchAgentResponse);
} catch (error) {
spinner.stop();
console.error(chalk.red('Error processing your request:'), error);
}
}
}

main();
21 changes: 21 additions & 0 deletions examples/agents/software-architecture-agent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "software-architecture-agent",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"baseai": "baseai"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@baseai/core": "^0.9.19",
"dotenv": "^16.4.5",
"inquirer": "^12.0.0",
"ora": "^8.1.0"
},
"devDependencies": {
"baseai": "^0.9.19"
}
}