Package: simple-ai-agents
Simple AI AgentsCreate simple multi-agent workflows using any LLMs - easy to experiment, use and deploy.The package extendsSimple AI Chatby adding support for100+ LLM providers,structured responsesand multiple agents, similar toAutogen. With out of the box handling of LLM requests, session handling and structured response generation, multi-agent conversations can be easily orchestrated with Python to manage the control flow. This results in code which is easy to understand and extend with minimal dependencies.Note: The package is in active development and the API is subject to change. To use, please clone the repo and install the package locally. It has not been published to PyPI yet. Better JSON support for other LLM models and the ability to save and load sessions are in the roadmap.FeaturesMix and match LLM providers (OpenAI, Huggingface, Ollama, Anthropic and more!).Create and run chats with only a few lines of code!Integrates withinstructorto provide structured responses for almost all models.Run multiple independent chats at once or createAutogenlike multi-agent conversations.Minimal codebase: no code dives to figure out what's going on under the hood needed!Async and streaming.Interactive CLI.Getting StartedAdd the necessary environment variables corresponding to theLLM providersthat will be used. Refer to.env.examplefor an example of the variables to add:OPENAI_API_KEY=<your openai api key>
OPENAI_ORGANIZATION=<your openai organization>
HUGGINGFACE_API_KEY=<your huggingfacehub api token>The package provides aChatAgentclass that can be used to create a chatbot:fromsimple_ai_agents.chat_agentimportChatAgentchatbot=ChatAgent(system="You are a helpful assistant")chatbot("Generate 2 random numbers between 0 to 100",console_output=True)chatbot("Which of the two numbers is bigger?",console_output=True)console_outputprovides a convenient way to print the chatbot's response to the console. By default, the chatbot uses theopenaiprovider. To use a different provider, pass thellm_optionsargument to theChatAgentconstructor. For example, to use the mistral model fromollama:fromsimple_ai_agents.modelsimportLLMOptionsmistral:LLMOptions={"model":"ollama/mistral","temperature":0.7,"api_base":"http://localhost:11434",}chatbot=ChatAgent(system="You are a helpful assistant",llm_options=mistral)The CLI offers an easy way to start a local chatbot session similar toSimple AI ChatorOllamabut with support for almost all LLM providers.See the examples folder for other use cases.CLIEnsure that you have the necessary environment variables set up. Usage:aichat[OPTIONS][PROMPT]The CLI supports the following options:--prime: Prime the chatbot with a prompt before starting the chat.--character: The name of the chat agent.--model: Specify the LLM model e.g. gpt-3.5-turbo, ollama/mistral etc. Uses gpt-3.5-turbo by default.--temperature: Specify the temperature for the LLM model. Uses 0.7 by default.--system: System prompt.--helpInteractive open-ended chataichat--primePass in prompts as argumentsUses a local instance of the mistral model fromollamato summarize the README file.catREADME.md|aichat--modelollama/mistral"Summarize this file"Looking for an option that is not available? Open an issue or submit a PR!Structured responsesTo generate a structured response, use thegen_modelmethod:classPerson(BaseModel):name:str=Field(description="Name of the person")age:int=Field(description="Age of the person")chatbot=ChatAgent(llm_options=openai)parsed=chatbot.gen_model("Extract `My name is John and I am 18 years old` into JSON",response_model=Person)The package automatically selects the best mode to generate JSON for a given provider and model:ProviderModeJSON StructureQuality of OutputOpen AIToolsExcellentExcellentAnyscaleJSON SchemaExcellentVery goodOllamaJSONExcellentVaries by modelOthersMD_JSONAcceptableVaries by modelCurrently,Open AIandAnyscaleare the only two providers with a structured response mode.Ollamaalso supports json response but the quality of the output is dependent on the model used (and probably whether it has been fine-tuned for json generation). For other providers, the package uses theMD_JSONmode which is a markdown representation of the JSON structure.ExamplesBasic chatbot sessionMultiple chatbot sessionsMulti-agent conversation with different modelsStructured responsesLLM as JudgeDevelopmentPoetryPackage management is handled bypoetry. Install it by following the instructionshere.Installing packagesAfter installingpoetry, install the project packages by running:poetryinstallSetting up pre-commit hooksPre-commit hooks automatically process your code prior to commit, enforcing consistency across the codebase without the need for manual intervention. Currently, these hooks are used:trailing-whitespace: trims trailing whitespacerequirements-txt-fixer: sorts entries in requirements.txtblack: to format the code consistentlyisort: to sort all imports consistentlyflake8: as a linterAll commits should pass the hooks above before being pushed.# Install the configured hookspoetryrunpre-commitinstall# Run the hooks on all files in the repopoetryrunpre-commitrun-aIf there are any failures, resolve them first, then stage and commit as usual. Committing will automatically trigger these hooks, and the commit will fail if there are unresolved errors.Run the testspoetryrunpytest