# OOBE-PROTOCOL + NEXTJS + LANGCHAIN

#### OOBE Protocol Integration in Next.js

Integrate `oobe-protocol` within the Next.js framework to use the agent instance from the backend. Initialize the core using the predefined method. We'll employ Langchain to support specific integrated functions of the agent.

**Steps**

1. **Export a Handler:** Define and export an asynchronous handler function as a backend route. This is essential for initializing the agent and obtaining responses from it.
2. **Verify Keys:** Ensure the `oobeKey = ''` *<mark style="color:red;">//empty string</mark>*, `openAiKey`, and `privateKey` are present. Return a `400` status with an error message if any are missing.
3. **Create OOBE Instance:** Use the `OobeCore` class with necessary parameters to create an OOBE instance. Set configurations using `ConfigManager`.
4. **Setup Streaming and Response:** Use the `TextEncoder` to stream events, handle different events like `"on_chat_model_stream"`, and write the encoded data to the response.
5. **Error Handling:** Implement error handling mechanisms to catch and log errors, returning appropriate responses.

By following these steps, you can effectively run the agent and retrieve execution responses, ensuring smooth and integrated backend operations with Next.js and OOBE protocol.<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://oobe-protocol.gitbook.io/oobe-protocol/getting-started/quickstart-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
