Skip to content

Commit

Permalink
Langchain added to documentation (#273)
Browse files Browse the repository at this point in the history
* Updated starter example

* Update openai-gpt.ipynb

* Update openai-gpt.ipynb

* Update openai-gpt.ipynb

* Update openai-gpt.ipynb

* Langchain added to documentation

Closes #270

---------

Co-authored-by: akj <[email protected]>
  • Loading branch information
albertkimjunior authored Jun 26, 2024
1 parent 6d17133 commit f8ccbdc
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"pages": [
"v1/integrations/crewai",
"v1/integrations/autogen",
"v1/integrations/langchain",
"v1/integrations/cohere",
"v1/integrations/litellm"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/integrations/autogen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Autogen has comprehensive [documentation](https://microsoft.github.io/autogen/do
```
</CodeGroup>
<Check>
[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub while you're at it (you may be our 1,000th 😊)
[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub while you're at it (you may be our 2,000th 😊)
</Check>
</Step>
<Step title="Install Autogen">
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/integrations/cohere.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This is a living integration. Should you need any added functionality message us
poetry add agentops
```
</CodeGroup>
<Check>[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub while you're at it (you may be our 1,000th 😊)</Check>
<Check>[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub while you're at it (you may be our 2,000th 😊)</Check>
</Step>
<Step title="Add 3 lines of code">
<CodeGroup>
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/integrations/crewai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Crew has comprehensive [documentation](https://docs.crewai.com) available as wel
```
</CodeGroup>
<Check>
[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub while you're at it (you may be our 1,000th 😊)
[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub while you're at it (you may be our 2,000th 😊)
</Check>
</Step>
<Step title="Install Crew from the AgentOps fork">
Expand Down
110 changes: 110 additions & 0 deletions docs/v1/integrations/langchain.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
title: Langchain
description: "AgentOps provides first class support for Lanchain applications"
---

AgentOps works seamlessly with applications built using Langchain.

## Adding AgentOps to Langchain applications

<Steps>
<Step title="Install the AgentOps SDK and the additional Langchain dependency">
<CodeGroup>
```bash pip
pip install agentops
pip install agentops[langchain]
```
```bash poetry
poetry add agentops
poetry add agentops[langchain]
```
</CodeGroup>
<Check>
[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub while you're at it (you may be our 2,000th 😊)
</Check>
</Step>
<Step title="Set up your import statements">
Import the following Langchain and AgentOps dependencies
<CodeGroup>
```python python
import os
from langchain.chat_models import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from agentops.langchain_callback_handler import LangchainCallbackHandler
```
</CodeGroup>
<Tip>
For more features see our [Usage](/v1/usage) section.
</Tip>
</Step>
<Step title="Set up your Langchain handler to make the calls">
Set up your Langchain agent with the AgentOps callback handler and AgentOps will automatically record your Langchain sessions.
<CodeGroup>
```python python
handler = LangchainCallbackHandler(api_key=AGENTOPS_API_KEY, tags=['Langchain Example'])

llm = ChatOpenAI(openai_api_key=OPENAI_API_KEY,
callbacks=[handler],
model='gpt-3.5-turbo')

agent = initialize_agent(tools,
llm,
agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
callbacks=[handler], # You must pass in a callback handler to record your agent
handle_parsing_errors=True)
```
</CodeGroup>
<Tip>
Note that you don't need to set up a separate agentops.init() call, as the Langchain callback handler will automatically initialize the AgentOps client for you.
</Tip>
</Step>
<Step title="Set your API key">
Retrieve an API Key from your Settings > [Projects & API Keys](https://app.agentops.ai/settings/projects) page.
<Frame type="glass" caption="Settings > Projects & API Keys">
<img height="200" src="/images/api-keys.png" />
</Frame>
<Info>
API keys are tied to individual projects.<br></br>
A Default Project has been created for you, so just click Copy API Key
</Info>
Set this API Key in your [environment variables](/v1/usage/environment-variables)
```python .env
AGENTOPS_API_KEY=<YOUR API KEY>
```
</Step>
<Step title="Run your agent">
Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your Langchain Agent! 🕵️
<Tip>
After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard
</Tip>
<div/>{/* Intentionally blank div for newline */}
<Frame type="glass" caption="Clickable link to session">
<img height="200" src="https://github.com/AgentOps-AI/agentops/blob/cf67191f13e0e2a09446a61b7393e1810b3eee95/docs/images/link-to-session.gif?raw=true" />
</Frame>
</Step>
</Steps>

## Full Examples

<CodeGroup>
```python python
import os
from langchain.chat_models import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from agentops.langchain_callback_handler import LangchainCallbackHandler

handler = LangchainCallbackHandler(api_key=AGENTOPS_API_KEY, tags=['Langchain Example'])

llm = ChatOpenAI(openai_api_key=OPENAI_API_KEY,
callbacks=[handler],
model='gpt-3.5-turbo')

agent = initialize_agent(tools,
llm,
agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
callbacks=[handler], # You must pass in a callback handler to record your agent
handle_parsing_errors=True)
```
</CodeGroup>
2 changes: 1 addition & 1 deletion docs/v1/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: "Build your next agent with evals, observability, and replays"
mode: "wide"
---

<Check>[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub if you find AgentOps helpful (you may be our 1,000th 😊)</Check>
<Check>[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub if you find AgentOps helpful (you may be our 2,000th 😊)</Check>

# AgentOps is your new terminal

Expand Down
3 changes: 1 addition & 2 deletions docs/v1/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import SupportedModels from '/snippets/supported-models.mdx'
poetry add agentops
```
</CodeGroup>
<Check>[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub while you're at it (you may be our 1,000th 😊)</Check>
</Step>
<Step title="Add 2 lines of code">
<CodeGroup>
Expand Down Expand Up @@ -61,7 +60,7 @@ import SupportedModels from '/snippets/supported-models.mdx'
</Frame>
</Step>
</Steps>

<Check>[Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub if you found AgentOps helpful (you may be our 2,000th 😊)</Check>

## More basic functionality

Expand Down

0 comments on commit f8ccbdc

Please sign in to comment.