> ## Documentation Index
> Fetch the complete documentation index at: https://docs.groundforge.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain Agent Example

> Connect the GroundForge demo Agent using automatic Channel input handling.

<Card title="groundforgeai/demo" icon="github" iconType="brands" href="https://github.com/groundforgeai/demo" horizontal cta="Open repository">
  The `simple_agent_service.py` example creates a LangChain Agent with a safe demo tool: `get_weather(city)`.
</Card>

## 1. Create the external Agent in GroundForge

In [platform.groundforge.ai](https://platform.groundforge.ai):

1. select the intended Organization and Workspace;
2. create an **External Agent**;
3. create a Service Account for the Agent process;
4. issue an Agent-targeted credential;
5. keep the stable external Agent ID, Organization ID, and Workspace ID.

> **Screenshot placeholder**\
> Add `/images/examples/external-agent-create.png` showing the External Agent form and runtime identity.

## 2. Clone and install

```bash theme={null}
git clone https://github.com/groundforgeai/demo.git
cd demo

python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install --upgrade langchain langchain-openai
python -m pip install ./groundforge_langchain-0.2.13-py3-none-any.whl
```

Use the SDK wheel supplied with your GroundForge release.

## 3. Set the connection values

```bash theme={null}
export GROUNDFORGE_ENDPOINT="https://platform.groundforge.ai"
export GROUNDFORGE_API_KEY="<agent-service-account-credential>"
export GROUNDFORGE_AGENT_ID="<stable-external-agent-id>"
export GROUNDFORGE_TENANT_ID="<organization-id>"
export GROUNDFORGE_WORKSPACE_ID="<workspace-id>"
export OPENAI_API_KEY="<openai-api-key>"
```

The demo does not require custom caller metadata. GroundForge sends the normalized Channel input, and automatic mode converts it into the Agent’s message input.

## 4. Run the Agent

```bash theme={null}
python simple_agent_service.py
```

The example uses:

```python theme={null}
params={"channelInputMode": "auto"}
```

Keep the process running. In GroundForge, confirm that the Agent is connected and Discovery lists `get_weather(city)`.

```bash theme={null}
gforge agents discovery <groundforge-agent-resource-id> -o yaml
```

> **Screenshot placeholder**\
> Add `/images/examples/langchain-agent-connected.png` showing connection state and `get_weather` in Discovery.

## 5. Attach a Channel

| Twilio WhatsApp                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Mailgun email                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Slack                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | JSON webhook                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <img src="https://mintcdn.com/groundforgeai/V4bCNZADLwZmOUhb/images/logos/twilio.svg?fit=max&auto=format&n=V4bCNZADLwZmOUhb&q=85&s=23137771bd5787e2f879be0b011b0f6f" alt="Twilio WhatsApp" width="180" height="52" data-path="images/logos/twilio.svg" /> | <img src="https://mintcdn.com/groundforgeai/V4bCNZADLwZmOUhb/images/logos/mailgun.svg?fit=max&auto=format&n=V4bCNZADLwZmOUhb&q=85&s=e44f0beff51cba2ce8e643efff40199b" alt="Mailgun email" width="190" height="52" data-path="images/logos/mailgun.svg" /> | <img src="https://mintcdn.com/groundforgeai/V4bCNZADLwZmOUhb/images/logos/slack.svg?fit=max&auto=format&n=V4bCNZADLwZmOUhb&q=85&s=bbd3c9f49d4ac80988ae7897c35bca1e" alt="Slack" width="170" height="52" data-path="images/logos/slack.svg" /> | <img src="https://mintcdn.com/groundforgeai/V4bCNZADLwZmOUhb/images/logos/webhook.svg?fit=max&auto=format&n=V4bCNZADLwZmOUhb&q=85&s=d78ae7cf3160792c859045b3c88be684" alt="JSON webhook" width="180" height="52" data-path="images/logos/webhook.svg" /> |

Choose [Twilio WhatsApp](/guides/twilio-whatsapp), [Mailgun](/guides/mailgun), Slack, or a JSON webhook. Attach the Channel to the Agent and publish the Agent before configuring the provider callback.

## 6. Send a request

```text theme={null}
What is the weather in Ottawa?
```

GroundForge sends the normalized request to the running Agent. The Agent selects `get_weather(city="Ottawa")`, the Gateway checks the rule, and the final response returns through the Channel.

## 7. Govern and trace the tool

Set `get_weather` to Observe, Review, or Block and send the same question again. Open the Trace to compare the paths.

Continue with [LangChain Agent with Adapters](/examples/langchain-adapter), [Govern the Weather Capability](/guides/tool-governance), and [Request Tracing](/guides/request-tracing).


## Related topics

- [Examples](/examples/index.md)
- [LangChain Agent with Adapters](/examples/langchain-adapter.md)
- [Connect a LangChain Agent](/sdk/langchain.md)
- [Agents](/concepts/agents.md)
