Coder Social home page Coder Social logo

bcg-x-official / agentkit Goto Github PK

View Code? Open in Web Editor NEW
1.4K 22.0 180.0 35.5 MB

Starter-kit to build constrained agents with Nextjs, FastAPI and Langchain

Home Page: https://agentkit.infra.x.bcg.com/

License: MIT License

Makefile 1.23% Dockerfile 0.54% Python 45.40% Mako 0.14% JavaScript 1.66% Shell 0.24% TypeScript 49.36% Gherkin 0.59% CSS 0.84%
fastapi full-stack genai genai-chatbot genai-poc langchain langchain-python nextjs openai react

agentkit's Introduction

AgentKit logo

Lint-Backend Lint-Frontend Tests

AgentKit: rapidly build high quality Agent apps

AgentKit is a LangChain-based starter kit developed by BCG X to build Agent apps. Developers can use AgentKit to

  • Quickly experiment on your constrained agent architecture with a beautiful UI
  • Build a full stack chat-based Agent app that can scale to production-grade MVP

Key advantages of the AgentKit toolkit include:

  • ๐Ÿš€ Quickly build high quality Agent apps: Build a strong demo in a few hours using a modular, easy to configure tech stack based on FastAPI/Nextjs and a library of useful GenAI tools
  • ๐Ÿ’ป Flexible, reactive UI/UX designed for Agents: React/Nextjs chat-based UI that is easy to configure, with features such as streaming, rendering of tables/visualizations/code, status of Agent actions and more
  • ๐Ÿ›ก๏ธ Focus on reliability: Easy to configure routing architecture gives control of possible paths Agent can take, increasing reliability and making it suited for real-life use cases
  • ๐Ÿ“ˆ Set up to scale: Set up to scale to MVP with ready made Queue Management, Auth, Caching, Monitoring etc.
AgentKit_Video.mp4

Tech stack

The starter pack is based on the latest technologies for optimal performance, security and developer experience.

  • ๐Ÿ’ซ Nextjs 14 with tailwind and daisyui
  • ๐Ÿ”ฅ Python 3.10 with fastapi, sqlmodel and pydantic 2.x.
  • ๐Ÿฆœ Langchain and Langsmith e2e configuration
  • ๐Ÿ— Authentication: NextAuth integrated with FastAPI
  • ๐Ÿฅฌ Celery and redis for long running tasks, caching etc.
  • ๐Ÿ’พ Local Postgres with pgvector extension
  • โฌ†๏ธ Docker-compose for simple deployments and DX
  • ๐Ÿ– Linting, tests and pre-commit hooks pre-configured

Quickstart

For a quick setup of AgentKit, use the steps below, where both the backend app and frontend app are run inside a Docker container. More elaborate setup instructions can be found in the documentation.

Prerequisites

Installation steps

  1. Clone the repository containing the source code for the backend and frontend apps.

  2. Copy the frontend/.env.example file in the frontend directory and change the name to .env. Also, copy the .env.example file in the root directory of the repository and change the name to .env.

    • Change the OPENAI_API_KEY and OPENAI_ORGANIZATION to your own (n.b. OPENAI_ORGANIZATION should be your OpenAI 'Organization ID')
  3. In the terminal, navigate to the root directory of the cloned repository. Build and start the Docker containers with the following command:

    docker-compose -f docker-compose.yml up -d
    

    Wait for the containers to build and start, which may take a few minutes depending on your system. Once the containers are up and running, you can access the apps in your browser at http://localhost.

Chinook music database demo

  • If docker containers are running, run docker-compose down --volumes
  • Follow the installation instructions above and swap docker-compose.yml with docker-compose-demo.yml to run the app
  • Try the prompt "How many artists and songs are there in the database?" to see AgentKit in action!

Check out a more advanced demo build following the tutorial.

Set up your own app

  • Configure your Agent and Tools link
  • (Optional) Adjust the UI to your use case link
  • (Optional) Set up evaluation with LangSmith link

Documentation

Find the hosted documentation here.

How it works

Reliability

AgentKit attempts to solve the reliability issue of agents such as ReAct agents by constraining the potential routes the agent can take to a pre-configured sets of routes, or Action Plans. Since for many use cases the potential routes the agent can take are known, we can use our human domain expertise to steer the agent in the right direction, and reduce it going into unexpected directions or rabbit holes. This is achieved by combining a Meta Agent with Action Plans: A set of tools which are executed linearly and in parallel, similar to a Chain. The Meta Agent takes in the user prompt and outputs the most suited Action Plan to generate an answer. Note: implementing multiple Meta Agents is possible, generating a tree of possible routes.

User experience

To optimize user experience, the intermediary output of every step in the Action Plan can be shown to the user. For example, consider an Action Plan consisting of 2 toolsets: [[sql_tool, pdf_tool], [generate_summary_tool, visualize_tool]]. In the first action step, information from a SQL database and a vector database with embedded PDFs are retrieved in parallel. The retrieved data and most relevant PDF are streamed to the UI as soon as the first action step finishes. In the second action step, the output from step 1 is passed to a tool that generates a text summary and a tool that creates a JSX visualization from the data, which is streamed to the UI to create the final answer.

For a high level overview of the routing flow and connection the UI, please see below diagram: AgentKit framework

Additional optional features

  • Feedback integration: collect feedback on generated answers from users

Feedback

  • User settings: Allow users to specify default settings in the app that can be used to customize prompts for the user

Feedback

  • User authentication: Enable NextAuth on your app to authenticate users with Github or with email/password

Feedback

See optional feature documentation for more detailed info.

Star History

Star History Chart

Support and Maintenance

The project spun of a combination of different templates. One great inspiration is fastapi-alembic-sqlmodel-async, which provided the foundations for the FastAPI setup. Please check them out!

Great thanks to all the contributors: @kaikun213 @drivian @ielmansouri @mastersplinter @tanmaygupta9 @sofglide @harticode @edenbd @ben-howt @carelschw @gustafvh @casper321 @modvinden1 @valerie-jzr @ispoljari @martinthenext

Please read CONTRIBUTING.md for more details on how to contribute. PRs are welcome โค๏ธ

License

License

  • This project is licensed under the terms of the MIT license

agentkit's People

Contributors

almirb avatar ben-howt avatar dependabot[bot] avatar drivian avatar harticode avatar ielmansouri avatar kaikun213 avatar mastersplinter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

agentkit's Issues

Docker compose doesn't go up

Describe the bug
After cloning the repository, updating the .env files, and adding my OpenAI key, the docker container doesn't load.

Steps To Reproduce
Steps to reproduce the behavior:
Follow the instructions in the readme using a new installation.

Expected behavior
Docker container loads without issues.

Screenshots
If applicable, add screenshots to help explain your problem.
Screenshot from 2024-04-04 03-14-31

Desktop (please complete the following information):

  • OS: Ubuntu
  • Python 3.11.6
  • Docker : version 24.0.5

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Missing library when running tests

Describe the bug
When trying to launch the tests suite after a fresh install, I get the following error: ValueError: the greenlet library is required to use this function. No module named 'greenlet'

Steps To Reproduce
Steps to reproduce the behavior:

  1. cd backend/app
  2. poetry install --with-dev
  3. poetry shell
  4. pytest -c tests/pytest.ini

Expected behavior
The test suite should run with no error.

Screenshots
image

Desktop (please complete the following information):

  • OS: MacOS 14.3.1

Additional context

  • poetry add greenlet fixed the isssue

failed to solve: changes out of order: "app/poetry.lock" ""

Im trying to execute:
docker-compose -f docker-compose.yml up -d
and i have the error:
`[+] Building 0.0s (0/0) docker:default
[+] Building 1.1s (5/10) docker:default
=> [fastapi_server internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 768B 0.0s
=> [fastapi_server internal] load metadata for docker.io/tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim-2022-11-25 1.1s
=> [fastapi_server internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [fastapi_server 1/6] FROM docker.io/tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim-2022-11-25@sha256:22589c7d5ce3755fc43e78496744c57e322581cc05d0c15421cada291 0.0s
=> ERROR [fastapi_server internal] load build context 0.0s
=> => transferring context: 36B 0.0s

[fastapi_server internal] load build context:


failed to solve: changes out of order: "app/poetry.lock" ""`

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Describe the bug
Error message, when starting:
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Seems Next/Node memory parameter is too small, in the Docker container.
I tried adding some NODE_OPTIONS to increase memory up to 4096M.
Got a different error, but still does not work.
At exact same place.

I expect it works out of the box.

Steps To Reproduce
When running command, as described in the documentation:
docker-compose -f docker-compose.yml up -d

Desktop (please complete the following information):

  • OS: MacOS
  • MacBook Air (Intel), last one before M1.
  • Browser: Brave
  • Python 3.11.5

Additional context
Logs:
[+] Building 110.8s (17/20) docker:desktop-linux
=> [nextjs_server internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 1.60kB 0.0s
=> [nextjs_server internal] load metadata for docker.io/library/node:18-alpine 1.7s
=> [nextjs_server auth] library/node:pull token for registry-1.docker.io 0.0s
=> [nextjs_server internal] load .dockerignore 0.0s
=> => transferring context: 113B 0.0s
=> [nextjs_server internal] load build context 0.2s
=> => transferring context: 471.94kB 0.1s
=> [nextjs_server base 1/1] FROM docker.io/library/node:18-alpine@sha256:ca9f6cb0466f9638e59e0c249d335a07c867cd50c429b5c7830dda1bed584649 0.0s
=> CACHED [nextjs_server runner 1/6] WORKDIR /app 0.0s
=> CACHED [nextjs_server runner 2/6] RUN addgroup --system --gid 1001 nodejs 0.0s
=> CACHED [nextjs_server runner 3/6] RUN adduser --system --uid 1001 nextjs 0.0s
=> CACHED [nextjs_server deps 1/4] RUN apk add --no-cache libc6-compat 0.0s
=> CACHED [nextjs_server deps 2/4] WORKDIR /app 0.0s
=> CACHED [nextjs_server deps 3/4] COPY package.json pnpm-lock.yaml* ./ 0.0s
=> CACHED [nextjs_server deps 4/4] RUN yarn global add pnpm && pnpm i --frozen-lockfile 0.0s
=> CACHED [nextjs_server builder 2/5] COPY --from=deps /app/node_modules ./node_modules 0.0s
=> [nextjs_server builder 3/5] COPY . . 0.2s
=> [nextjs_server builder 4/5] RUN yarn run prisma:generate 7.0s
=> ERROR [nextjs_server builder 5/5] RUN yarn run build 101.4s

[nextjs_server builder 5/5] RUN yarn run build:
0.837 yarn run v1.22.19
0.950 $ next build
3.208 Attention: Next.js now collects completely anonymous telemetry regarding usage.
3.208 This information is used to shape Next.js' roadmap and prioritize features.
3.208 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
3.209 https://nextjs.org/telemetry
3.209
3.463 Skipping validation of types
3.464 Linting ...
20.16
20.16 ./src/components/Common/Drawer/Drawer.tsx
20.16 4:1 Warning: @react-hookz/web import should occur before import of framer-motion import/order
20.16
20.16 ./src/components/ConversationView/MessageView/MessageEvents/MessageEvent/LLMResponse.tsx
20.16 4:1 Warning: ~/components/ConversationView/ConversationView.selectors import should occur before import of ../../../../CustomIcons/Icon import/order
20.16 52:17 Warning: Classnames 'mb-1, mt-1' could be replaced by the 'my-1' shorthand! tailwindcss/enforces-shorthand
20.16
20.16 info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
20.21 โ–ฒ Next.js 14.0.4
20.21 - Environments: .env
20.21
20.21 Creating an optimized production build ...
68.59
68.60 โ•ญโ”€โ”€ ๐ŸŒผ daisyUI 3.9.4 https://daisyui.com
69.33 โ”‚
69.33 โ”œโ”€โ”€ prefix is enabled, daisyUI classnames must use daisy prefix. like: daisybtn
69.33 โ”‚ https://daisyui.com/docs/config
69.33 โ”‚
69.33 โ”œโ”€โ”€ 2 themes are enabled. How to add more themes:
69.33 โ”‚ https://daisyui.com/docs/themes
69.33 โ”‚
69.33 โ•ฐโ”€โ”€ โญ๏ธ Star daisyUI project on GitHub: https://github.com/saadeghi/daisyui
69.33
69.83
69.83 โ•ญโ”€โ”€ ๐ŸŒผ daisyUI 3.9.4 https://daisyui.com
70.07 โ”‚
70.07 โ”œโ”€โ”€ prefix is enabled, daisyUI classnames must use daisy prefix. like: daisybtn
70.07 โ”‚ https://daisyui.com/docs/config
70.07 โ”‚
70.07 โ”œโ”€โ”€ 2 themes are enabled. How to add more themes:
70.07 โ”‚ https://daisyui.com/docs/themes
70.07 โ”‚
70.07 โ•ฐโ”€โ”€ โญ๏ธ Star daisyUI project on GitHub: https://github.com/saadeghi/daisyui
70.07
70.51
70.51 โ•ญโ”€โ”€ ๐ŸŒผ daisyUI 3.9.4 https://daisyui.com
70.73 โ”‚
70.73 โ”œโ”€โ”€ prefix is enabled, daisyUI classnames must use daisy prefix. like: daisybtn
70.73 โ”‚ https://daisyui.com/docs/config
70.73 โ”‚
70.73 โ”œโ”€โ”€ 2 themes are enabled. How to add more themes:
70.73 โ”‚ https://daisyui.com/docs/themes
70.73 โ”‚
70.73 โ•ฐโ”€โ”€ โญ๏ธ Star daisyUI project on GitHub: https://github.com/saadeghi/daisyui
70.73
100.1
100.1 <--- Last few GCs --->
100.1
100.1 [27:0x7fc20fca8030] 98218 ms: Mark-sweep (reduce) 728.1 (749.7) -> 726.8 (745.2) MB, 472.2 / 0.0 ms (+ 213.5 ms in 49 steps since start of marking, biggest step 11.4 ms, walltime since start of marking 745 ms) (average mu = 0.414, current mu = 0.278) [27:0x7fc20fca8030] 99017 ms: Mark-sweep (reduce) 727.9 (745.2) -> 727.1 (745.7) MB, 793.5 / 0.0 ms (average mu = 0.245, current mu = 0.008) allocation failure; scavenge might not succeed
100.1
100.1
100.1 <--- JS stacktrace --->
100.1
100.1 FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
100.8 error Command failed with signal "SIGABRT".
100.8 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


failed to solve: process "/bin/sh -c yarn run build" did not complete successfully: exit code: 1

Update calls of `arun` to `ainvoke` for langchain chat models

Using the arun methods to call a chat model -- which is what we currently do -- gives the following warning: LangChainDeprecationWarning: The function arun was deprecated in LangChain 0.1.0 and will be removed in 0.2.0. Use ainvoke instead.

arun will be removed in langchain==0.2.0 (currently at 0.1.14) so we should update this sooner rather than later

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.