Skip to main content

Integrating TaskGuru with LangChain

The TaskGuru API is explicitly designed as a state-management and memory layer for autonomous AI agents. If you are building with LangChain (Python or TypeScript) or LangGraph, TaskGuru can serve as the visual dashboard for your agents, allowing human oversight of complex, multi-step workflows.

Why use TaskGuru with LangChain?

Most LangChain agents struggle with state persistence across long-running tasks. By hooking your agent into TaskGuru:
  1. Visual State Management: Humans can see exactly what the agent is working on via the TaskGuru Kanban boards.
  2. Human-in-the-Loop Workflow: Your agent can pause execution, assign a TaskGuru ticket to a human for approval, and resume when the ticket status changes to COMPLETED.
  3. Conversational Memory per Task: Using our messages endpoint, the agent can store its scratchpad reasoning directly on the Task thread.

๐Ÿš€ Quick Start: OpenAPI Agent (Python)

The easiest way to connect LangChain to TaskGuru is by using our hosted OpenAPI specification. LangChain can read this spec and automatically figure out how to call our endpoints.

Prerequisites

First, install the required packages:
pip install langchain langchain-openai requests

1. Initialize the TaskGuru Agent

In this example, weโ€™ll give LangChain the ability to read your TaskGuru boards and create tasks automatically.
import os
from langchain.agents.agent_toolkits.openapi import create_openapi_agent
from langchain.agents.agent_toolkits.openapi.spec import reduce_openapi_spec
from langchain.requests import RequestsWrapper
from langchain_openai import ChatOpenAI

# 1. Provide your TaskGuru Personal Access Token
headers = {
    "Authorization": f"Bearer {os.environ.get('TASKGURU_API_KEY')}",
    "Content-Type": "application/json"
}

# 2. Setup the Requests Wrapper with Auth
requests_wrapper = RequestsWrapper(headers=headers)

# 3. Load the TaskGuru OpenAPI Spec
# (Assuming the spec is hosted at docs.taskguru.com or loaded locally)
import yaml
with open("openapi.yaml", "r") as f:
    raw_taskguru_api_spec = yaml.load(f, Loader=yaml.Loader)

taskguru_spec = reduce_openapi_spec(raw_taskguru_api_spec)

# 4. Initialize the LLM
llm = ChatOpenAI(model_name="gpt-4-turbo", temperature=0)

# 5. Create the Agent
agent = create_openapi_agent(
    taskguru_spec,
    requests_wrapper,
    llm,
    verbose=True
)

# 6. Execute the Agent
agent.run("Find my 'Backend Refactor' board and create an urgent task called 'Migrate User Table'.")

๐Ÿง  Advanced: LangGraph Human-in-the-Loop

If you are building complex state machines with LangGraph, you can use TaskGuru to implement a literal โ€œHuman-in-the-Loopโ€ fallback. When the agent attempts a dangerous action (like executing raw SQL or sending an email), it can create a Task in TaskGuru assigned to a human, and sleep.

Polling for Task Completion (JavaScript/TypeScript Example)

import { TaskGuru } from "@taskguru/sdk"; // Example SDK import
import { delay } from "./utils";

const tg = new TaskGuru(process.env.TASKGURU_API_KEY);

async function requireHumanApproval(
  boardId: string,
  context: string,
): Promise<boolean> {
  // 1. Create the task for the human
  const approvalTask = await tg.tasks.create({
    name: "๐Ÿšจ URGENT: Require Human Approval for DB Migration",
    description: `The AI agent is attempting to run the following migration:\n\n\`\`\`sql\n${context}\n\`\`\`\n\nPlease review and mark this task as COMPLETED to authorize.`,
    board_id: boardId,
    urgency: "urgent",
  });

  console.log(`Waiting for human to approve task: ${approvalTask.id}`);

  // 2. Poll TaskGuru until the human marks it as COMPLETED
  while (true) {
    await delay(30000); // Check every 30 seconds
    const checkTask = await tg.tasks.get(approvalTask.id);

    if (checkTask.status === "COMPLETED") {
      console.log("Human approved! Resuming execution.");
      return true;
    }

    // Optional: Log an update to the task thread so the human knows the agent is still waiting
    await tg.messages.create(approvalTask.id, {
      content: "AI Agent: Still humming by. Let me know when you approve this!",
    });
  }
}

Next Steps

To understand exactly which fields LangChain is accessing, review the OpenAPI Reference.