MCPcopy Create free account
hub / github.com/microsoft/TypeChat

github.com/microsoft/TypeChat @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
659 symbols 1,938 edges 125 files ⚖ MIT 88 documented · 13% 7 cross-repo links updated 2d ago★ 8,67957 open issues

Browse by type

Functions 361 Types & classes 298
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TypeChat

TypeChat is a library that makes it easy to build natural language interfaces using types.

Building natural language interfaces has traditionally been difficult. These apps often relied on complex decision trees to determine intent and collect the required inputs to take action. Large language models (LLMs) have made this easier by enabling us to take natural language input from a user and match to intent. This has introduced its own challenges including the need to constrain the model's reply for safety, structure responses from the model for further processing, and ensuring that the reply from the model is valid. Prompt engineering aims to solve these problems, but comes with a steep learning curve and increased fragility as the prompt increases in size.

TypeChat replaces prompt engineering with schema engineering.

Simply define types that represent the intents supported in your natural language application. That could be as simple as an interface for categorizing sentiment or more complex examples like types for a shopping cart or music application. For example, to add additional intents to a schema, a developer can add additional types into a discriminated union. To make schemas hierarchical, a developer can use a "meta-schema" to choose one or more sub-schemas based on user input.

After defining your types, TypeChat takes care of the rest by:

  1. Constructing a prompt to the LLM using types.
  2. Validating the LLM response conforms to the schema. If the validation fails, repair the non-conforming output through further language model interaction.
  3. Summarizing succinctly (without use of a LLM) the instance and confirm that it aligns with user intent.

Types are all you need!

Getting Started

Install TypeChat for TypeScript/JavaScript:

npm install typechat

You can also work with TypeChat from source for:

To see TypeChat in action, we recommend exploring the TypeChat example projects. You can try them on your local machine or in a GitHub Codespace.

To learn more about TypeChat, visit the documentation which includes more information on TypeChat and how to get started.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 262
Class 189
Interface 105
Method 99
Enum 4

Languages

Python50%
TypeScript50%

Modules by API surface

python/examples/music/schema.py36 symbols
tools/scripts/fix-dependabot-alerts.mjs32 symbols
python/examples/music/spotipyWrapper.py24 symbols
typescript/examples/music/src/endpoints.ts23 symbols
python/src/typechat/_internal/ts_conversion/python_type_to_ts_nodes.py21 symbols
typescript/examples/music/src/trackFilter.ts19 symbols
typescript/examples/music/src/trackCollections.ts19 symbols
typescript/src/zod/validate.ts17 symbols
python/tests/test_coffeeshop.py17 symbols
typescript/examples/coffeeShop/src/coffeeShopSchema.ts16 symbols
python/tests/coffeeshop_deprecated.py16 symbols
python/examples/music/client.py16 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

@11ty/eleventy3.1.2 · 1×
@types/express4.17.17 · 1×
@types/find-config1.0.4 · 1×
@types/node20.10.4 · 1×
@types/spotify-api0.0.22 · 1×
axios1.16.0 · 1×
chalk2.3.1 · 1×
copyfiles2.4.1 · 1×
dotenv16.3.1 · 1×
express4.18.2 · 1×
find-config1.0.0 · 1×
music0.0.1 · 1×

For agents

$ claude mcp add TypeChat \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page