1- ### Langroid + Groq
1+ ## How to use Langroid Multi-Agent Framework with Groq
2+
23[ Langroid] ( https://github.com/langroid/langroid ) is an
34open-source Python framework that simplifies building LLM applications,
45using a Multi-Agent paradigm.
56
67You can now use Langroid with Groq, by setting the model name to
78` groq/<model> ` , e.g., ` groq/llama3-70b-8192 ` .
89
9- To get started, create a virtual environment using Python 3.11:
10+ To get started, create a virtual environment using Python 3.11 and Langroid:
1011
1112
1213``` bash
1314python3 -m venv .venv
1415. ./.venv/bin/activate
1516pip install --upgrade langroid
1617````
17- Place your ` GROQ_API_KEY` in a ` .env` file in the root directory of this project,
18- it should have a line that looks like:
18+
19+ Place your ` GROQ_API_KEY` in a ` .env` file in the root directory of this project.
20+ If you don' t have one, you can create an account on GroqCloud and
21+ generate one for free at https://console.groq.com.
22+ Your `.env` file should have a line that looks like the following:
23+
1924```
2025GROQ_API_KEY=gsk_...
2126```
2227Or you can set explicitly set this key in your environment before
2328running the scripts.
2429
25- Below is a bare-bones code example.
30+ ### Simple code examples using Langroid with a Groq-hosted LLM
31+
32+ Here is how you can specify a Groq-hosted LLM with Langroid, and directly
33+ "chat" with the LLM
34+
2635
2736```python
2837import langroid as lr
@@ -36,19 +45,32 @@ llm_config = lm.OpenAIGPTConfig(
3645llm = lm.OpenAIGPT(llm_config)
3746
3847llm.chat("3+4=?").message
48+ ```
3949
50+ The `llm` does _not_ maintain conversation state, so you must invoke `chat()` with
51+ a sequence of user-assistant messages. Langroid has a convenient `ChatAgent` abstraction
52+ that maintains this state for you:
53+ ```python
4054agent_config = lr.ChatAgentConfig(
4155 llm=llm_config,
4256 system_message="""Be nice but concise""",
4357)
4458
4559agent = lr.ChatAgent(agent_config)
60+ response = agent.llm_response("Capital of France?")
61+ # follow-up question works since agent maintains conversation history
62+ response = agent.llm_response("What about Congo?")
63+ ```
64+
65+ Finally, you can wrap an agent in a `Task` to run it in an interactive chat loop.
66+ Here' s all you need to make a basic chat-bot using Langroid:
67+ ` ` ` python
4668task = lr.Task(agent, interactive=True)
4769task.run ()
4870` ` `
4971
5072An example script showing a 2-agent assistant is included in this folder.
51- The langroid repo has numerous example scripts as well, and you can run them
52- against a groq -hosted LLM by changing ` chat_model ` to ` groq/llama3-70b-8192 ` (as an
73+ The Langroid repo has numerous example scripts as well, and you can run them
74+ against a Groq -hosted LLM by changing ` chat_model` to ` groq/llama3-70b-8192` (as an
5375example). Many of the scripts also take a command-line argument ` -m` to specify the
5476model, e.g. ` -m groq/llama3-70b-8192` .
0 commit comments