From ca2c0e2a6d2ff6973352f00643fc08ec6e9f7d7f Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 30 Oct 2024 02:13:46 +0100 Subject: [PATCH 1/8] added gitignore --- examples/agents/software-architecture-agent/.gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 examples/agents/software-architecture-agent/.gitignore diff --git a/examples/agents/software-architecture-agent/.gitignore b/examples/agents/software-architecture-agent/.gitignore new file mode 100644 index 00000000..1a041e0b --- /dev/null +++ b/examples/agents/software-architecture-agent/.gitignore @@ -0,0 +1,9 @@ +# baseai +**/.baseai/ +node_modules +.env +package-lock.json +pnpm-lock.yaml +# env file +# env file +.env From 40700a8fc23c76f5d625b68477ff5b4c7c3f2361 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 30 Oct 2024 02:14:00 +0100 Subject: [PATCH 2/8] added baseai env file --- .../.env.baseai.example | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/agents/software-architecture-agent/.env.baseai.example diff --git a/examples/agents/software-architecture-agent/.env.baseai.example b/examples/agents/software-architecture-agent/.env.baseai.example new file mode 100644 index 00000000..b0d9e992 --- /dev/null +++ b/examples/agents/software-architecture-agent/.env.baseai.example @@ -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= From 169157659cf51694eeac6f009f2a411abfd325b9 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 30 Oct 2024 02:14:24 +0100 Subject: [PATCH 3/8] main cli for software-architecture-agent --- .../software-architecture-agent/index.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 examples/agents/software-architecture-agent/index.ts diff --git a/examples/agents/software-architecture-agent/index.ts b/examples/agents/software-architecture-agent/index.ts new file mode 100644 index 00000000..0a99372a --- /dev/null +++ b/examples/agents/software-architecture-agent/index.ts @@ -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(); From 941e53e907077020d45defe8fe29dda72bf75554 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 30 Oct 2024 02:14:34 +0100 Subject: [PATCH 4/8] added packaged for software-architecture-agent --- .../software-architecture-agent/package.json | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/agents/software-architecture-agent/package.json diff --git a/examples/agents/software-architecture-agent/package.json b/examples/agents/software-architecture-agent/package.json new file mode 100644 index 00000000..97ad1739 --- /dev/null +++ b/examples/agents/software-architecture-agent/package.json @@ -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" + } +} From 6e8e18662a0cca7081761dff1ca510ea523f5c2b Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 30 Oct 2024 02:15:14 +0100 Subject: [PATCH 5/8] added readme for software-architecture-agent --- .../software-architecture-agent/README.md | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 examples/agents/software-architecture-agent/README.md diff --git a/examples/agents/software-architecture-agent/README.md b/examples/agents/software-architecture-agent/README.md new file mode 100644 index 00000000..372993ec --- /dev/null +++ b/examples/agents/software-architecture-agent/README.md @@ -0,0 +1,79 @@ +![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 +``` + +## 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]
+**_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 From 2e9adc518638cfb0d23b6f6681083caab3827a6d Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 30 Oct 2024 02:15:59 +0100 Subject: [PATCH 6/8] swtiched off logs by default --- .../baseai/baseai.config.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/agents/software-architecture-agent/baseai/baseai.config.ts diff --git a/examples/agents/software-architecture-agent/baseai/baseai.config.ts b/examples/agents/software-architecture-agent/baseai/baseai.config.ts new file mode 100644 index 00000000..3c0328bc --- /dev/null +++ b/examples/agents/software-architecture-agent/baseai/baseai.config.ts @@ -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' +}; From b9cf311de712769dd6d9f4132a9e6d021dcf2c14 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 30 Oct 2024 02:18:54 +0100 Subject: [PATCH 7/8] updated readme --- examples/agents/software-architecture-agent/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/agents/software-architecture-agent/README.md b/examples/agents/software-architecture-agent/README.md index 372993ec..5095edbd 100644 --- a/examples/agents/software-architecture-agent/README.md +++ b/examples/agents/software-architecture-agent/README.md @@ -31,6 +31,8 @@ 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 From 5e0eeafabf3419b231dd057501cec25cc9f9fa87 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 30 Oct 2024 02:19:30 +0100 Subject: [PATCH 8/8] pipe configuration for software-architecture-agent --- .../pipes/software-architecture-agent.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/agents/software-architecture-agent/baseai/pipes/software-architecture-agent.ts diff --git a/examples/agents/software-architecture-agent/baseai/pipes/software-architecture-agent.ts b/examples/agents/software-architecture-agent/baseai/pipes/software-architecture-agent.ts new file mode 100644 index 00000000..43e5bc52 --- /dev/null +++ b/examples/agents/software-architecture-agent/baseai/pipes/software-architecture-agent.ts @@ -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 \n \n \n \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;