diff --git a/examples/agents/talk-to-excel-sheets-agent/.env.baseai.example b/examples/agents/talk-to-excel-sheets-agent/.env.baseai.example new file mode 100644 index 00000000..8c643651 --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/.env.baseai.example @@ -0,0 +1,21 @@ +# !! 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= diff --git a/examples/agents/talk-to-excel-sheets-agent/.gitignore b/examples/agents/talk-to-excel-sheets-agent/.gitignore new file mode 100644 index 00000000..9b5994f6 --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/.gitignore @@ -0,0 +1,9 @@ +# baseai +**/.baseai/ +node_modules +.env +package-lock.json +pnpm-lock.yaml +# env file +.env + diff --git a/examples/agents/talk-to-excel-sheets-agent/README.md b/examples/agents/talk-to-excel-sheets-agent/README.md new file mode 100644 index 00000000..4e920c51 --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/README.md @@ -0,0 +1,85 @@ +![Talk To Excel Agent by ⌘ BaseAI][cover] + +![License: MIT][mit] [![Fork on ⌘ Langbase][fork]][pipe] + +## Build a Talk To Excel Agent with BaseAI framework — ⌘ Langbase + +The **Talk To Excel Agent** is an BaseAI powered data analysis tool that streamlines your Excel workflows by automatically analyzing uploaded files to provide comprehensive overviews and actionable insights. Utilizing BaseAI's memory and tool call features, it delivers detailed summaries of data structure, identifies patterns and trends, and highlights potential data quality issues. + +The agent guides you toward meaningful analysis by suggesting key areas for deeper exploration and assisting in refining queries. Additionally, you can combine this agent with the Excel Formula Generation Agent to access a suite of powerful tools for analyzing your financial data effectively without losing sight of the bigger picture. Configurable through the baseai.config.ts file, logging is disabled by default. By bridging the gap between business questions and technical Excel operations, the Talk To Excel Agent empowers you to make data-driven decisions efficiently and effectively. + +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/talk-to-excel-sheets-agent` and run the following commands: + +```sh +# Navigate to baseai/examples/agents/it-systems-triage-agent +cd examples/agents/talk-to-excel-sheets-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: Please provide openai and anthropic API key to run this example +cp .env.baseai.example .env + +# Run the local baseai dev server to test the examples (uses localhost:9000 port) +npx baseai@latest dev + +# Create local embeddings of the sample file provided +npx baseai@latest embed -m talk-to-excel-memory + +# Run the agent +npx tsx index.ts +``` + +## Features + +- Talk To Excel 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]). +- Talk To Excel Agent uses [BaseAI memory][memory] and [tool calls][toolcalls] feature. + +## 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/talk-to-excel-agent +[gh]: https://github.com/LangbaseInc/baseai/tree/main/examples/agents/talk-to-excel-sheets-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/talk-to-excel-sheets-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 \ No newline at end of file diff --git a/examples/agents/talk-to-excel-sheets-agent/baseai/baseai.config.ts b/examples/agents/talk-to-excel-sheets-agent/baseai/baseai.config.ts new file mode 100644 index 00000000..3c0328bc --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-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' +}; diff --git a/examples/agents/talk-to-excel-sheets-agent/baseai/memory/talk-to-excel-memory/Sample-Sales-Data.xlsx b/examples/agents/talk-to-excel-sheets-agent/baseai/memory/talk-to-excel-memory/Sample-Sales-Data.xlsx new file mode 100644 index 00000000..04ac8aba Binary files /dev/null and b/examples/agents/talk-to-excel-sheets-agent/baseai/memory/talk-to-excel-memory/Sample-Sales-Data.xlsx differ diff --git a/examples/agents/talk-to-excel-sheets-agent/baseai/memory/talk-to-excel-memory/documents/Sample-Sales-Data.csv b/examples/agents/talk-to-excel-sheets-agent/baseai/memory/talk-to-excel-memory/documents/Sample-Sales-Data.csv new file mode 100644 index 00000000..efc6b4d6 --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/baseai/memory/talk-to-excel-memory/documents/Sample-Sales-Data.csv @@ -0,0 +1,391 @@ +Postcode,Sales_Rep_ID,Sales_Rep_Name,Year,Value +2121,456,Jane,2011,"$84,219" +2092,789,Ashish,2012,"$28,322" +2128,456,Jane,2013,"$81,879" +2073,123,John,2011,"$44,491" +2134,789,Ashish,2012,"$71,838" +2162,123,John,2013,"$64,532" +2093,456,Jane,2011,"$58,963" +2042,789,Ashish,2012,"$27,522" +2198,123,John,2013,"$77,985" +2043,789,Ashish,2011,"$49,546" +2025,789,Ashish,2012,"$17,734" +2045,456,Jane,2013,"$91,126" +2090,456,Jane,2011,"$48,113" +2114,456,Jane,2012,"$28,361" +2142,456,Jane,2013,"$50,912" +2062,123,John,2011,"$75,539" +2049,456,Jane,2012,"$96,922" +2204,456,Jane,2013,"$57,838" +2000,456,Jane,2011,"$4,530" +2135,123,John,2012,"$27,761" +2115,456,Jane,2013,"$22,773" +2032,789,Ashish,2011,"$98,780" +2068,456,Jane,2012,"$66,044" +2119,789,Ashish,2013,"$32,882" +2060,456,Jane,2011,"$75,822" +2072,456,Jane,2012,"$36,675" +2045,123,John,2013,"$95,817" +2140,456,Jane,2011,"$43,627" +2205,789,Ashish,2012,"$93,306" +2060,123,John,2013,"$71,322" +2042,456,Jane,2011,"$92,023" +2118,123,John,2012,"$40,655" +2137,789,Ashish,2013,"$95,518" +2021,789,Ashish,2011,"$24,550" +2044,123,John,2012,"$65,166" +2008,789,Ashish,2013,"$52,576" +2142,789,Ashish,2011,"$2,356" +2027,456,Jane,2012,"$11,444" +2110,456,Jane,2013,"$30,569" +2137,123,John,2011,"$83,085" +2164,789,Ashish,2012,"$82,490" +2067,789,Ashish,2013,"$23,819" +2100,123,John,2011,"$60,571" +2032,456,Jane,2012,"$81,538" +2038,789,Ashish,2013,"$51,840" +2011,123,John,2011,"$8,502" +2143,789,Ashish,2012,"$41,610" +2170,456,Jane,2013,"$10,063" +2049,789,Ashish,2011,"$87,702" +2086,456,Jane,2012,"$99,436" +2032,123,John,2013,"$88,957" +2203,123,John,2011,"$18,846" +2198,456,Jane,2012,"$70,963" +2112,456,Jane,2013,"$45,571" +2052,456,Jane,2011,"$12,148" +2133,456,Jane,2012,"$30,272" +2164,456,Jane,2013,"$62,744" +2087,789,Ashish,2011,$106 +2065,456,Jane,2012,"$30,815" +2008,456,Jane,2013,"$89,093" +2137,456,Jane,2011,"$22,748" +2162,456,Jane,2012,"$8,396" +2016,789,Ashish,2013,"$64,711" +2099,789,Ashish,2011,"$25,131" +2040,456,Jane,2012,"$79,001" +2034,789,Ashish,2013,"$32,184" +2044,789,Ashish,2011,"$72,567" +2190,789,Ashish,2012,"$18,508" +2205,123,John,2013,"$69,531" +2006,123,John,2011,"$63,822" +2190,456,Jane,2012,"$80,225" +2132,789,Ashish,2013,"$33,048" +2147,123,John,2011,"$36,421" +2006,789,Ashish,2012,"$73,725" +2062,456,Jane,2013,"$30,811" +2134,123,John,2011,"$33,404" +2110,789,Ashish,2012,"$60,876" +2165,789,Ashish,2013,"$37,754" +2009,123,John,2011,"$22,853" +2195,789,Ashish,2012,"$5,535" +2029,123,John,2013,"$42,456" +2199,123,John,2011,"$91,204" +2068,123,John,2012,"$3,038" +2009,456,Jane,2013,"$85,747" +2043,456,Jane,2011,"$81,013" +2046,456,Jane,2012,"$6,259" +2050,456,Jane,2013,"$80,519" +2047,789,Ashish,2011,"$79,290" +2114,123,John,2012,"$69,906" +2041,789,Ashish,2013,"$57,233" +2023,456,Jane,2011,"$77,798" +2094,456,Jane,2012,"$42,384" +2022,123,John,2013,"$39,847" +2026,456,Jane,2011,"$36,794" +2007,123,John,2012,"$10,190" +2064,456,Jane,2013,"$52,484" +2023,123,John,2011,"$12,963" +2125,789,Ashish,2012,"$79,116" +2070,123,John,2013,"$16,574" +2092,456,Jane,2011,"$27,554" +2040,789,Ashish,2012,"$37,597" +2096,123,John,2013,"$59,562" +2123,456,Jane,2011,"$59,035" +2200,456,Jane,2012,"$36,868" +2099,456,Jane,2013,"$1,839" +2166,456,Jane,2011,"$97,072" +2160,123,John,2012,"$16,914" +2048,456,Jane,2013,"$49,053" +2030,123,John,2011,"$19,847" +2093,789,Ashish,2012,"$33,781" +2127,456,Jane,2013,"$18,870" +2160,456,Jane,2011,"$68,071" +2119,456,Jane,2012,"$51,034" +2088,456,Jane,2013,"$64,901" +2029,789,Ashish,2011,"$47,448" +2038,456,Jane,2012,"$16,708" +2046,789,Ashish,2013,"$63,444" +2070,789,Ashish,2011,"$62,106" +2089,123,John,2012,"$9,348" +2139,123,John,2013,"$2,676" +2117,789,Ashish,2011,"$12,348" +2109,123,John,2012,"$95,787" +2141,456,Jane,2013,"$28,465" +2115,789,Ashish,2011,"$28,358" +2196,123,John,2012,"$66,107" +2093,123,John,2013,"$69,062" +2129,789,Ashish,2011,"$9,997" +2068,789,Ashish,2012,"$13,716" +2136,456,Jane,2013,"$8,607" +2113,123,John,2011,"$31,430" +2195,123,John,2012,"$74,719" +2134,456,Jane,2013,"$28,814" +2194,789,Ashish,2011,"$11,589" +2017,456,Jane,2012,"$15,792" +2122,789,Ashish,2013,"$62,984" +2066,456,Jane,2011,"$12,902" +2203,789,Ashish,2012,"$68,657" +2150,789,Ashish,2013,"$44,106" +2121,789,Ashish,2011,"$5,491" +2142,123,John,2012,"$78,419" +2117,456,Jane,2013,"$4,380" +2096,456,Jane,2011,"$70,422" +2162,789,Ashish,2012,"$18,159" +2041,456,Jane,2013,"$11,743" +2127,123,John,2011,"$11,934" +2128,789,Ashish,2012,"$95,799" +2034,456,Jane,2013,"$36,756" +2166,789,Ashish,2011,"$47,447" +2133,123,John,2012,"$41,256" +2170,789,Ashish,2013,"$2,676" +2135,456,Jane,2011,"$94,182" +2116,123,John,2012,"$49,808" +2144,123,John,2013,"$22,950" +2144,456,Jane,2011,"$54,906" +2133,789,Ashish,2012,"$14,909" +2034,123,John,2013,"$46,115" +2112,123,John,2011,"$81,701" +2143,123,John,2012,"$37,556" +2203,456,Jane,2013,"$85,516" +2111,123,John,2011,"$31,844" +2037,456,Jane,2012,"$49,010" +2018,456,Jane,2013,"$19,506" +2145,123,John,2011,"$42,691" +2100,456,Jane,2012,"$28,370" +2041,123,John,2013,"$26,094" +2129,456,Jane,2011,"$48,260" +2197,789,Ashish,2012,"$95,119" +2060,789,Ashish,2013,"$53,020" +2198,789,Ashish,2011,"$10,619" +2191,789,Ashish,2012,"$59,382" +2047,123,John,2013,"$1,126" +2010,123,John,2011,"$40,301" +2146,789,Ashish,2012,"$43,403" +2143,456,Jane,2013,"$74,226" +2206,789,Ashish,2011,"$1,425" +2071,123,John,2012,"$5,592" +2095,123,John,2013,"$55,937" +2024,123,John,2011,"$12,638" +2146,123,John,2012,"$98,511" +2110,123,John,2013,"$73,319" +2044,456,Jane,2011,"$59,483" +2165,456,Jane,2012,"$45,309" +2039,789,Ashish,2013,"$71,498" +2140,789,Ashish,2011,"$32,218" +2122,456,Jane,2012,"$81,655" +2152,123,John,2013,"$34,023" +2096,789,Ashish,2011,"$9,782" +2031,789,Ashish,2012,"$96,343" +2011,456,Jane,2013,"$73,529" +2094,123,John,2011,"$90,268" +2111,456,Jane,2012,"$51,310" +2123,123,John,2013,"$45,923" +2015,123,John,2011,"$19,274" +2199,456,Jane,2012,"$89,797" +2025,123,John,2013,"$52,643" +2028,123,John,2011,"$39,759" +2025,456,Jane,2012,"$82,466" +2197,456,Jane,2013,"$21,515" +2151,789,Ashish,2011,"$76,684" +2007,789,Ashish,2012,"$18,008" +2015,789,Ashish,2013,"$22,374" +2024,789,Ashish,2011,"$69,425" +2017,123,John,2012,"$47,309" +2050,789,Ashish,2013,"$54,726" +2160,789,Ashish,2011,"$35,361" +2030,456,Jane,2012,"$87,640" +2153,123,John,2013,"$95,990" +2150,123,John,2011,"$95,860" +2151,123,John,2012,"$20,564" +2045,789,Ashish,2013,$429 +2027,789,Ashish,2011,"$15,533" +2010,456,Jane,2012,"$35,901" +2132,123,John,2013,"$54,435" +2052,123,John,2011,"$33,363" +2088,789,Ashish,2012,"$10,350" +2095,456,Jane,2013,"$29,959" +2016,123,John,2011,$219 +2071,456,Jane,2012,"$68,776" +2138,789,Ashish,2013,"$33,064" +2049,123,John,2011,"$89,721" +2090,789,Ashish,2012,"$89,379" +2021,456,Jane,2013,"$64,328" +2039,123,John,2011,"$25,195" +2031,456,Jane,2012,"$67,431" +2016,456,Jane,2013,"$46,975" +2029,456,Jane,2011,"$92,118" +2040,123,John,2012,"$91,204" +2061,456,Jane,2013,"$85,200" +2191,456,Jane,2011,"$18,627" +2052,789,Ashish,2012,"$52,173" +2129,123,John,2013,"$23,169" +2152,789,Ashish,2011,"$12,455" +2161,789,Ashish,2012,"$87,957" +2090,123,John,2013,"$41,928" +2153,789,Ashish,2011,"$92,728" +2109,789,Ashish,2012,"$42,205" +2018,123,John,2013,"$36,659" +2091,456,Jane,2011,"$34,479" +2199,789,Ashish,2012,"$25,315" +2000,789,Ashish,2013,"$83,706" +2204,789,Ashish,2011,"$99,744" +2043,123,John,2012,"$63,982" +2073,789,Ashish,2013,"$34,376" +2121,123,John,2011,"$54,647" +2028,456,Jane,2012,"$62,273" +2147,789,Ashish,2013,"$23,528" +2037,123,John,2011,"$13,588" +2028,789,Ashish,2012,"$31,935" +2128,123,John,2013,"$38,554" +2063,789,Ashish,2011,"$15,322" +2115,123,John,2012,"$8,072" +2192,456,Jane,2013,"$56,303" +2048,789,Ashish,2011,"$99,878" +2094,789,Ashish,2012,"$20,724" +2118,789,Ashish,2013,"$42,536" +2166,123,John,2011,"$81,440" +2144,789,Ashish,2012,"$34,312" +2163,789,Ashish,2013,"$58,998" +2195,456,Jane,2011,"$22,991" +2141,789,Ashish,2012,"$87,835" +2114,789,Ashish,2013,"$68,606" +2000,123,John,2011,"$29,852" +2200,789,Ashish,2012,"$12,876" +2138,456,Jane,2013,"$90,142" +2066,123,John,2011,"$82,467" +2008,123,John,2012,"$26,125" +2022,789,Ashish,2013,"$98,200" +2048,123,John,2011,"$87,567" +2061,789,Ashish,2012,"$31,230" +2193,123,John,2013,"$79,938" +2113,789,Ashish,2011,"$70,310" +2131,123,John,2012,"$35,670" +2010,789,Ashish,2013,"$95,019" +2015,456,Jane,2011,"$79,888" +2116,789,Ashish,2012,"$46,537" +2069,456,Jane,2013,"$69,285" +2112,789,Ashish,2011,"$75,682" +2033,456,Jane,2012,"$39,497" +2064,123,John,2013,"$27,992" +2161,123,John,2011,"$41,023" +2190,123,John,2012,"$63,170" +2007,456,Jane,2013,"$2,299" +2163,456,Jane,2011,"$10,715" +2153,456,Jane,2012,"$17,557" +2092,123,John,2013,"$28,856" +2039,456,Jane,2011,"$55,998" +2086,789,Ashish,2012,"$34,228" +2204,123,John,2013,"$19,759" +2047,456,Jane,2011,"$99,865" +2206,123,John,2012,"$37,002" +2009,789,Ashish,2013,"$86,506" +2197,123,John,2011,"$64,203" +2062,789,Ashish,2012,"$95,386" +2206,456,Jane,2013,"$53,130" +2119,123,John,2011,"$5,597" +2017,789,Ashish,2012,"$86,749" +2132,456,Jane,2013,"$80,783" +2066,789,Ashish,2011,"$65,530" +2072,789,Ashish,2012,"$29,271" +2088,123,John,2013,"$67,072" +2196,456,Jane,2011,"$53,379" +2163,123,John,2012,"$62,579" +2006,456,Jane,2013,"$24,773" +2030,789,Ashish,2011,"$19,130" +2087,456,Jane,2012,"$72,141" +2089,456,Jane,2013,"$67,958" +2196,789,Ashish,2011,"$60,644" +2138,123,John,2012,"$61,285" +2139,456,Jane,2013,"$91,989" +2194,456,Jane,2011,"$60,771" +2086,123,John,2012,"$26,038" +2122,123,John,2013,"$13,475" +2038,123,John,2011,"$82,932" +2061,123,John,2012,"$40,690" +2170,123,John,2013,"$36,190" +2135,789,Ashish,2011,"$46,689" +2131,789,Ashish,2012,"$30,040" +2091,123,John,2013,"$57,250" +2042,123,John,2011,"$38,292" +2205,456,Jane,2012,"$10,554" +2150,456,Jane,2013,"$73,270" +2070,456,Jane,2011,"$58,038" +2067,456,Jane,2012,"$42,027" +2130,123,John,2013,"$1,513" +2091,789,Ashish,2011,"$32,610" +2021,123,John,2012,"$16,080" +2063,123,John,2013,"$52,398" +2131,456,Jane,2011,"$66,041" +2117,123,John,2012,"$45,504" +2100,789,Ashish,2013,"$55,365" +2147,456,Jane,2011,"$81,415" +2161,456,Jane,2012,"$59,929" +2095,789,Ashish,2013,"$48,058" +2139,789,Ashish,2011,"$63,168" +2123,789,Ashish,2012,"$68,917" +2064,789,Ashish,2013,"$27,360" +2125,456,Jane,2011,"$98,235" +2152,456,Jane,2012,"$31,709" +2111,789,Ashish,2013,"$39,711" +2046,123,John,2011,"$73,978" +2113,456,Jane,2012,"$40,581" +2200,123,John,2013,"$58,858" +2027,123,John,2011,"$17,271" +2191,123,John,2012,"$7,711" +2165,123,John,2013,"$11,815" +2050,123,John,2011,"$55,591" +2065,789,Ashish,2012,"$83,495" +2023,789,Ashish,2013,"$71,676" +2069,789,Ashish,2011,"$42,792" +2069,123,John,2012,"$44,478" +2151,456,Jane,2013,"$71,535" +2146,456,Jane,2011,"$1,255" +2037,789,Ashish,2012,"$41,512" +2145,789,Ashish,2013,"$56,898" +2145,456,Jane,2011,"$72,324" +2071,789,Ashish,2012,"$80,893" +2192,123,John,2013,"$11,248" +2140,123,John,2011,"$89,202" +2026,789,Ashish,2012,"$37,881" +2033,123,John,2013,"$87,068" +2099,123,John,2011,"$82,290" +2125,123,John,2012,"$35,987" +2089,789,Ashish,2013,"$89,069" +2136,123,John,2011,"$83,059" +2022,456,Jane,2012,"$1,246" +2067,123,John,2013,"$57,863" +2127,789,Ashish,2011,"$70,494" +2118,456,Jane,2012,"$13,243" +2065,123,John,2013,"$88,485" +2193,789,Ashish,2011,"$82,687" +2073,456,Jane,2012,"$3,158" +2026,123,John,2013,"$55,339" +2011,789,Ashish,2011,"$43,356" +2087,123,John,2012,"$9,483" +2024,456,Jane,2013,"$43,002" +2192,789,Ashish,2011,"$24,078" +2109,456,Jane,2012,"$45,719" +2130,789,Ashish,2013,"$51,693" +2194,123,John,2011,"$66,864" +2141,123,John,2012,"$54,683" +2136,789,Ashish,2013,$882 +2033,789,Ashish,2011,"$76,990" +2072,123,John,2012,"$35,366" +2063,456,Jane,2013,"$93,341" +2018,789,Ashish,2011,"$97,168" +2164,123,John,2012,"$88,885" +2193,456,Jane,2013,"$79,440" +2031,123,John,2011,"$65,644" +2130,456,Jane,2012,"$66,248" +2116,456,Jane,2013,"$3,196" diff --git a/examples/agents/talk-to-excel-sheets-agent/baseai/memory/talk-to-excel-memory/index.ts b/examples/agents/talk-to-excel-sheets-agent/baseai/memory/talk-to-excel-memory/index.ts new file mode 100644 index 00000000..a4318d7d --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/baseai/memory/talk-to-excel-memory/index.ts @@ -0,0 +1,9 @@ +import { MemoryI } from '@baseai/core'; +import path from 'path'; + +const memoryTalkToExcelMemory = (): MemoryI => ({ + name: 'talk-to-excel-memory', + description: 'Sample excel file for analysis with BaseAI memory and tools call support', +}); + +export default memoryTalkToExcelMemory; diff --git a/examples/agents/talk-to-excel-sheets-agent/baseai/pipes/excel-analysis-agent.ts b/examples/agents/talk-to-excel-sheets-agent/baseai/pipes/excel-analysis-agent.ts new file mode 100644 index 00000000..d144f79b --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/baseai/pipes/excel-analysis-agent.ts @@ -0,0 +1,43 @@ +import { PipeI } from '@baseai/core'; + +const pipeExcelAnalysisAgent = (): PipeI => ({ + // Replace with your API key https://langbase.com/docs/api-reference/api-keys + apiKey: process.env.LANGBASE_API_KEY!, + name: `excel-analysis-agent`, + description: ``, + status: `private`, + model: `anthropic:claude-3-5-sonnet-latest`, + stream: false, + json: false, + store: true, + moderate: true, + top_p: 1, + max_tokens: 3000, + temperature: 0.41, + presence_penalty: 0, + frequency_penalty: 0, + stop: [], + tool_choice: 'auto', + parallel_tool_calls: false, + messages: [ + { + role: 'system', + content: + "You are a data analysis expert generating Danfo.js code (Only ES6 and above code is acceptable) for Excel analysis. You DONOT NEED TO DECLARE XLS_PATH variable as it has already been declared just use it. Generate code following this exact pattern and ensure that:\n\n1. **File Reading:**\n - Use the `XLS_PATH` variable to read the Excel file it is already provided but outside your context.\n - Utilize `dfd.readExcel` for file reading.\n - Do **not** include any import or require statements.\n\n2. **Function Structure:**\n - The main analysis function should return the analysis object properly.\n - Include error handling to capture and return any errors encountered during execution. \n\n3. **Data Analysis:**\n - Use only the validated DataFrame methods listed below.\n - Perform comprehensive analysis including overview and quick insights for single sheet currently in the Excel file.\n\n4. **Execution:**\n - End the script by returning the result of the analysis function to ensure the output is captured correctly.\n\n**Validated DataFrame Methods:**\n- `df.shape`\n- `df.columns`\n- `df.dtypes`\n- `df.describe()`\n- `df.head()`\n- `df.tail()`\n- `df.loc[]`\n- `df.groupby()`\n- `df.sort_values()`\n- `df.apply()`\n- `df.mean()`\n- `df.sum()`\n- `df.dropna()`\n- `df.unique()`\n\n**IMPORTANT:**\n- **Do NOT include any import or require statements.**\n- **Always use the provided `XLS_PATH` variable. It is defined outside of your generated script context.**\n- **Ensure the script handles cases where sheets are entirely missing or contain no data.**\n- **Ensure that the result of the analysis function is returned properly.**\n\n**Here is a valid tested template to Follow:**\n\n```javascript\nimport * as dfd from \"danfojs-node\";\nimport path from 'path';\n\nconst XLS_PATH = path.join(process.cwd(), 'baseai/memory/talk-to-excel-memory/documents/Sample-Sales-Data.xlsx');\n\nasync function analyzeExcelData() {\n try {\n // Read Excel file\n const df = await dfd.readExcel(XLS_PATH);\n \n // Validate DataFrame\n if (!df || !df.shape || df.shape[0] === 0) {\n return { error: \"No valid data found in the Excel file.\" };\n }\n\n const analysis = {\n overview: {\n dimensions: df.shape,\n columns: df.columns,\n types: df.dtypes\n },\n insights: {\n summary: dfd.toJSON(df.describe(), { format: 'row' }),\n preview: dfd.toJSON(df.head(), { format: 'row' })\n }\n };\n\n // Add numerical column analysis if available\n const numericCols = df.columns.filter(col => \n df.dtypes[col] === 'float64' || df.dtypes[col] === 'int64'\n );\n\n if (numericCols.length > 1) {\n const numericDf = df.loc({ columns: numericCols });\n analysis.insights.statistics = {\n mean: dfd.toJSON(numericDf.mean(), { format: 'row' }),\n sum: dfd.toJSON(numericDf.sum(), { format: 'row' })\n };\n }\n\n return analysis;\n } catch (error) {\n return { error: error.message };\n }\n}\n\n// Execute the analysis function and handle the results\nreturn analyzeExcelData()\n```" + + }, + { 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 pipeExcelAnalysisAgent; diff --git a/examples/agents/talk-to-excel-sheets-agent/baseai/pipes/talk-to-excel-agent.ts b/examples/agents/talk-to-excel-sheets-agent/baseai/pipes/talk-to-excel-agent.ts new file mode 100644 index 00000000..e295a9de --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/baseai/pipes/talk-to-excel-agent.ts @@ -0,0 +1,45 @@ +import { PipeI } from '@baseai/core'; +import callScriptAgentTool from '../tools/call-script-agent'; +import memoryTalkToExcelMemory from '../memory/talk-to-excel-memory'; +import toolExecuteJs from '../tools/execute-js'; + +const pipeTalkToExcelAgent = (): PipeI => ({ + // Replace with your API key https://langbase.com/docs/api-reference/api-keys + apiKey: process.env.LANGBASE_API_KEY!, + name: `talk-to-excel-agent`, + description: ``, + status: `private`, + model: `openai:gpt-4o-mini`, + stream: false, + json: false, + store: true, + moderate: true, + top_p: 1, + max_tokens: 4096, + temperature: 0.38, + presence_penalty: 0, + frequency_penalty: 0, + stop: [], + tool_choice: 'auto', + parallel_tool_calls: true, + messages: [ + { + role: 'system', + content: + 'You are an expert data analyst specializing in Excel data analysis. Use your initial analysis on the data on subsequent user queries in order to make effective tools call. \n\nYour primary role is to:\n1. Analyze Excel files uploaded by users\n2. Provide initial data insights\n3. Guide users toward meaningful analysis\n4. Help refine queries for formula generation\n5. Bridge the gap between business questions and technical Excel operations\n\n# Initial Analysis Protocol\nWhen a user uploads an Excel file, automatically provide:\n\n1. Data Overview:\n- Sheet and its name\n- Row and column counts\n- Data types present\n- Date ranges if applicable\n- Key column identifications\n- Missing data patterns\n\n2. Quick Insights:\n- Notable patterns or trends\n- Potential data quality issues\n- Unusual values or outliers\n- Basic statistical summaries of numerical columns\n- Relationships between different columns\n\n\n\n# Interaction Guidelines\n\n## First Interaction\n1. Present the initial analysis in a structured, easy-to-understand format\n2. Highlight 2-3 potentially interesting areas for deeper analysis\n3. Ask specific questions about the user\'s analytical goals 4. Before presenting your first analysis you will make a tool call: "call_script_agent" with all the questions that you need for your initial analysis and wait for the tool call to return the response then you will another tool call:"executeJs" that will execute the script from call_script_agent, you will wait to the results to return as this will have answers for you to reconcile. \n\nExample First Response:\n```\nI\'ve analyzed your Excel file. Here\'s what I found:\n\n📊 Data Structure:\n- 3 sheets: Sales, Inventory, Customers\n- Sales sheet: 1,200 rows × 8 columns\n- Primary data types: dates, currency, categorical\n\n🔍 Key Observations:\n1. Sales data spans Jan 2023 - Dec 2023\n2. 3 product categories identified\n3. Notable seasonality in sales patterns\n\n💡 Potential Areas for Analysis:\n1. Sales trend analysis by product category\n2. Customer purchase frequency patterns\n3. Inventory turnover rates\n\nWhat specific aspects of this data would you like to explore further?\n```\n\n## Follow-up Interactions\n\n1. Query Refinement:\n- Break down complex questions into analyzable components\n- Suggest specific metrics or approaches\n- Translate business questions into analytical frameworks\n\n2. Formula Guidance:\nWhen users need Excel formulas, provide:\n- Clear description of the analysis needed\n- Key variables and relationships to consider\n- Refined query suitable for an Excel formula generator\n\nExample Query Refinement:\n```\nUser: "I want to see how sales are performing"\n\nYour Response:\n"Let me help refine this analysis. We could look at:\n\n1. Month-over-month sales growth\n2. Sales performance by:\n - Product category\n - Customer segment\n - Geographic region\n3. Comparison against targets/previous periods\n\nWhich aspect would you like to focus on? Once you decide, I can help formulate a specific query for getting the exact Excel formulas needed."\n```\n\n# Analysis Framework\n\n## Data Insights Hierarchy:\n1. Descriptive (What happened?)\n- Basic trends\n- Pattern identification\n- Summary statistics\n\n2. Diagnostic (Why did it happen?)\n- Correlation analysis\n- Factor comparison\n- Anomaly investigation\n\n3. Predictive (What might happen?)\n- Trend projections\n- Pattern extrapolation\n- Scenario suggestions\n\n## Response Structure:\n1. Acknowledge user\'s question\n2. Provide initial insights\n3. Suggest deeper analysis paths\n4. Offer refined query for formula generation\n5. Ask clarifying questions if needed\n\n# Special Considerations\n\n1. Data Privacy:\n- Never suggest sharing sensitive data\n- Focus on analysis methods rather than specific values\n- Use placeholder values in examples\n\n2. Technical Limitations:\n- Acknowledge when certain analyses require additional data\n- Suggest alternative approaches when necessary\n- Be clear about analytical assumptions\n\n3. User Guidance:\n- Provide context for suggested analyses\n- Explain why certain approaches are recommended\n- Help users understand the business implications of findings\n\n# Error Handling\n\nWhen encountering issues:\n1. Clearly explain the limitation or problem\n2. Offer alternative approaches\n3. Guide user toward more answerable questions\n4. Suggest data improvements if relevant\n\nExample Error Response:\n```\nI notice the sales dates are inconsistent. For better analysis, I suggest:\n1. Standardizing date formats\n2. Checking for missing periods\n3. Verifying data entry patterns\n\nWould you like guidance on how to address these issues before proceeding with the analysis?\n```' + }, + { 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: [callScriptAgentTool(), toolExecuteJs()], + memory: [memoryTalkToExcelMemory()] +}); + +export default pipeTalkToExcelAgent; diff --git a/examples/agents/talk-to-excel-sheets-agent/baseai/tools/call-script-agent.ts b/examples/agents/talk-to-excel-sheets-agent/baseai/tools/call-script-agent.ts new file mode 100644 index 00000000..32bc7d46 --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/baseai/tools/call-script-agent.ts @@ -0,0 +1,34 @@ +import { ToolI, Pipe } from '@baseai/core'; +import pipeExcelAnalysisAgent from '../pipes/excel-analysis-agent'; + +const pipe = new Pipe(pipeExcelAnalysisAgent()); + +export async function call_script_agent({customerQuery}: {customerQuery: string}) { + // Your tool logic here + const excelAnalysisAgentResp = await pipe.run({ + messages: [{ role: 'user', content: customerQuery }], + }); + + return excelAnalysisAgentResp.completion; +} + +const callScriptAgentTool = (): ToolI => ({ + run: call_script_agent, // Name of the function to run + type: 'function' as const, + function: { + name: `call_script_agent`, + description: `Call this function to provide analysis of the attached excel file with danfo.js script`, + parameters: { + type: 'object', + properties: { + customerQuery: { + type: 'string', + description: 'JavaScript danfo.js script for data analysis' + } + }, + required: ['customerQuery'] + } + } +}); + +export default callScriptAgentTool; diff --git a/examples/agents/talk-to-excel-sheets-agent/baseai/tools/execute-js.ts b/examples/agents/talk-to-excel-sheets-agent/baseai/tools/execute-js.ts new file mode 100644 index 00000000..d119029d --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/baseai/tools/execute-js.ts @@ -0,0 +1,71 @@ +import { ToolI } from '@baseai/core'; +import * as dfd from "danfojs-node"; +import path from 'path'; + +const CSV_PATH = path.join(process.cwd(), 'baseai/memory/talk-to-excel-memory/documents/Sample-Sales-Data.csv'); +const XLS_PATH = path.join(process.cwd(), 'baseai/memory/talk-to-excel-memory/Sample-Sales-Data.xlsx'); + +export async function executeJs({ script }: { script: string }) { + try { + // Clean the script by removing import statements + let cleanedScript = script + .replace(/import.*?;/g, '') + .replace(/danfo\./g, 'dfd.') + .replace(/const XLS_PATH.*?;/g, ''); + + // Additional cleaning: remove any semicolons at the end + cleanedScript = cleanedScript.trim(); + if (!cleanedScript.endsWith(';')) { + cleanedScript += ';'; + } + + // Validate that cleanedScript is not empty + if (!cleanedScript) { + throw new Error('The cleaned script is empty. Please check the generated script.'); + } + + // Create function with dfd and XLS_PATH context + const scriptFn = new Function('dfd', 'XLS_PATH', ` + return (async () => { + try { + ${cleanedScript} + } catch (err) { + return { error: err.message }; + } + })(); + `); + + // Execute with dfd and XLS_PATH available + const result = await scriptFn(dfd, XLS_PATH); + console.log('Analysis Results:', JSON.stringify(result, null, 2)); + return { result }; + + } catch (error) { + console.error('Error during script execution:', error); + return { + result: { error: error instanceof Error ? error.message : 'Unknown error during script execution' } + }; + } +} + + +const toolExecuteJs = (): ToolI => ({ + run: executeJs, + type: 'function' as const, + function: { + name: 'executeJs', + description: 'Execute danfo.js script for data analysis on Excel data', + parameters: { + type: 'object', + properties: { + script: { + type: 'string', + description: 'The Danfo.js script to execute (dependencies will be provided)' + } + }, + required: ['script'] + } + } +}); + +export default toolExecuteJs; diff --git a/examples/agents/talk-to-excel-sheets-agent/index.ts b/examples/agents/talk-to-excel-sheets-agent/index.ts new file mode 100644 index 00000000..8938cfb5 --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-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 pipeTalkToExcelAgent from './baseai/pipes/talk-to-excel-agent'; + + +const pipe = new Pipe(pipeTalkToExcelAgent()); + +async function main() { + const initialSpinner = ora( + 'Connecting to talk-to-excel-agent...', + ).start(); + // Messages array for keeping track of the conversation + const messages: Message[] = [ + // Initial message to the agent + {role: 'user', content: 'Please provide your initial analysis?'}, + ]; + + 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: talkToExcelAgentResp} = await pipe.run({ + messages, + }); + messages.push({ + role: 'assistant', + content: talkToExcelAgentResp, + }); + spinner.stop(); + console.log(chalk.cyan('Agent:')); + console.log(talkToExcelAgentResp); + } catch (error) { + spinner.stop(); + console.error(chalk.red('Error processing your request:'), error); + } + } +} + +main(); diff --git a/examples/agents/talk-to-excel-sheets-agent/package.json b/examples/agents/talk-to-excel-sheets-agent/package.json new file mode 100644 index 00000000..af59e340 --- /dev/null +++ b/examples/agents/talk-to-excel-sheets-agent/package.json @@ -0,0 +1,25 @@ +{ + "name": "talk-to-excel-agent", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "baseai": "baseai" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "@baseai/core": "^0.9.3", + "danfojs-node": "^1.1.2", + "dotenv": "^16.4.5", + "inquirer": "^12.0.0", + "ora": "^8.1.0", + "tsx": "^4.19.2", + "xlsx": "^0.18.5" + }, + "devDependencies": { + "baseai": "^0.9.3" + } +}