Reusable core components for mchat
Project description
mchat_core
A collection of convenience functions for using LLM models and autogen agents driven by configuration files. Primarily used in MChat but written to be useful in a variety of use cases.
Installation and Usage
Dependencies are declared in pyproject.toml. Development and dependency management are primarily done using uv.
The [tools] dependency group includes additional requirements for bundled LLM Module tools. You only need these if you plan on using the provided tools.
Optional Tools Dependencies
- With uv (recommended):
- uv sync --group tools
- With pip (install only what you need - see pyproject.toml)
- pip install tzlocal fredapi chromadb beautifulsoup4
Running Tests
- Run all tests:
- pytest
- Show skip reasons:
- pytest -rs
- Run only the tools tests:
- pytest -m tools -rs
- Exclude tools tests:
- pytest -m "not tools"
Note: Tool tests are marked with the “tools” marker and will auto-skip if optional packages are not installed.
Configuration
Note: This code is actively developed. Instructions and sample configs may become outdated.
See the examples.ipynb notebook for more details
Configuration is managed in three files:
settings.toml.secrets.toml(optional but recommended)agents.yaml
Edit settings.toml to configure your application. Here’s a guide to the available options:
Models
Sections should start with models. (with a period) and contain no other periods in the section name.
Format: models.type.model_id — model_id will appear in list of available models
[models.chat.gpt-4o]
api_key = "@format {this.openai_api_key}"
model = "gpt-4o"
api_type = "open_ai"
base_url = "https://api.openai.com/v1"
NOTE: Image models and settings here are only for explicitly calling image models from prompts. The
generate_imagetool uses only the API key.
Required Fields
Chat Models
api_type: "open_ai" or "azure"model_type: "chat"model: Name of the modelapi_key: Your key or Dynaconf lookupbase_url: (if required by API)
Azure Chat Models (additional)
azure_endpoint: URL for your endpointazure_deployment: Deployment name for the modelapi_version: API version
Image Models
api_type: "open_ai" or "azure"model_type: "image"model: Name of the modelsize: Size of images to generatenum_images: Number of images to generateapi_key: Your key or Dynaconf lookup
Default Settings
default_model: Default model to usedefault_temperature: Default temperature for generationdefault_persona: Default persona for generation
Memory Model Configuration (Currently Disabled)
mchat can maintain conversational memory for long chats. When memory size exceeds model limits, conversations are summarized using a designated model (ideally, a cost-effective one).
Configurable properties:
memory_model: Model ID used for memory (should match one inmodels)memory_model_temperature: Temperature for memory summarizationmemory_model_max_tokens: Token limit for memory model
Secrets Configuration
Some sensitive config settings (like API keys) should be in .secrets.toml:
# .secrets.toml
# dynaconf_merge = true
# Replace the following with your actual API keys
# openai_models_api_key = "oai_ai_api_key_goes_here"
# ms_models_api_key = "ms_openai_api_key_goes_here"
Agents & Teams
mchat provides:
- A default persona
- Example agents: linux computer & financial manager
- Example teams: round-robin and selector
You can add more agents and teams at the top level in agents.yaml (same directory as this README), following the structure in mchat/default_personas.yaml.
When configuring personas, the extra_context list lets you define multi-shot prompts—see the linux computer persona in mchat/default_personas.json for an example.
Contributing
Thank you for considering contributing to the project! To contribute, please follow these guidelines:
-
Fork the repository and clone it to your local machine.
-
Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-name
Replace
your-feature-namewith a descriptive name for your contribution. -
Make the necessary changes and ensure that your code follows the project's coding conventions and style guidelines - which currently are using PEP 8 for style and black for formatting
-
Commit your changes with a clear and descriptive commit message:
git commit -m "Add your commit message here"
-
Push your branch to your forked repository:
git push origin feature/your-feature-name
-
Open a pull request from your forked repository to the main repository's
mainbranch. -
Provide a clear and detailed description of your changes in the pull request. Include any relevant information that would help reviewers understand your contribution.
License
This project is licensed under the MIT License.
Contact
Feel free to reach out to me at @jspv on GitHub
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mchat_core-0.1.1.tar.gz.
File metadata
- Download URL: mchat_core-0.1.1.tar.gz
- Upload date:
- Size: 36.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a21baead2151e4ee6b10b338ef3d4a8b1d16b564be652ad6699162fa52c6fb1
|
|
| MD5 |
b9a6132e09b86da03164cd0d7cd1cdf4
|
|
| BLAKE2b-256 |
b0bdbfd8818e7f593858c6c3ade0a25778812344d074d39774c29ce60418a179
|
File details
Details for the file mchat_core-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mchat_core-0.1.1-py3-none-any.whl
- Upload date:
- Size: 31.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4db933d3a5c8be9302f290f5f6d36e00bd07508ecc7d78dd64bfcd0f3af35cf1
|
|
| MD5 |
582d6bd58b6c5f8c7fe2bff510b42fec
|
|
| BLAKE2b-256 |
2cd3ace920b89ed1416c9022126baf04bab8d406b876019bbe820479fb74e354
|