new-agent

A code generator for LangGraph agents, which are AI programs that can call tools and follow defined steps. It offers a simpler high-level agent template and a lower-level StateGraph template for custom routing.

In plain words
What is it for?
Use it to create an agent file, choose between the two LangGraph styles, and then replace the example tools with your own logic.
Why use it?
It gives developers a prepared Python starting point with common setup and example tools already included.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/codeblockz/langchain-community-plugin/new-agent
Clone the repo
git clone --depth 1 https://github.com/Codeblockz/langchain-community-plugin
Per session 13 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,237 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00013 $0.01237
Opus 5 $0.00006 $0.00619
Sonnet 5 $0.00003 $0.00247
Haiku 4.5 $0.00001 $0.00124

Measured yesterday against content hash 09f5598f35bc, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

new-agent scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/new-agent.md · 217 lines

How it starts

The opening of the file, as written. The whole thing — 217 lines — stays where its author put it; the contents beside it link to each section on GitHub.

New LangGraph Agent Command

Create a new LangGraph agent file with best practices baked in.

Workflow

  1. Ask the user which agent type they want:

    • create_agent - High-level API, simpler, uses middleware
    • StateGraph - Low-level API, full control, custom routing
  2. Get filename from argument or ask user (default: agent.py)

  3. Generate the agent file using the appropriate template below

  4. Inform user about next steps (install dependencies, customize tools)

Templates

create_agent Template

"""
LangGraph Agent using create_agent API

Install: pip install langchain langgraph
"""
from langchain.agents import create_agent
from langchain.tools import tool
from langgraph.checkpoint.memory import InMemorySaver


# Define your tools
@tool
def search(query: str) -> str:
    """Search for information.

    Args:
        query: The search query
    """
    # TODO: Implement search logic
    return f"Results for: {query}"


@tool
def calculate(expression: str) -> str:
    """Evaluate a mathematical expression.

    Args:
        expression: Math expression to evaluate
    """
    # TODO: Implement safely
    return str(eval(expression))


# Create the agent
agent = create_agent(
    model="claude-sonnet-4-5-20250929",  # or "gpt-4o"
    tools=[search, calculate],
    system_prompt="You are a helpful assistant.",
    checkpointer=InMemorySaver(),  # Required for memory/HITL
)


def main():
    # Invoke with thread_id for conversation memory
    config = {"configurable": {"thread_id": "user-123"}}

    result = agent.invoke(
        {"messages": [{"role": "user", "content": "Hello!"}]},
        config=config
    )

    for msg in result["messages"]:
        print(f"{msg.type}: {msg.content}")


if __name__ == "__main__":
    main()

StateGraph Template

"""
LangGraph Agent using StateGraph API

Install: pip install langchain langgraph
"""
from typing import Annotated, Literal
from typing_extensions import TypedDict

from langchain.messages import AnyMessage, HumanMessage, SystemMessage
from langchain.chat_models import init_chat_model
from langchain.tools import tool
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langgraph.checkpoint.memory import InMemorySaver


# 1. Define state - MUST be TypedDict
class State(TypedDict):
    messages: Annotated[list[AnyMessage], add_messages]  # Reducer appends messages


# 2. Define tools
@tool
def search(query: str) -> str:
    """Search for information.

    Args:
        query: The search query
    """
    # TODO: Implement search logic
    return f"Results for: {query}"


@tool
def calculate(expression: str) -> str:
    """Evaluate a mathematical expression.

    Args:
        expression: Math expression to evaluate
    """
    # TODO: Implement safely
    return str(eval(expression))


# 3. Setup model with tools
tools = [search, calculate]
tools_by_name = {t.name: t for t in tools}
model = init_chat_model("claude-sonnet-4-5-20250929").bind_tools(tools)


# 4. Define nodes
def call_model(state: State) -> dict:
    """Call the model and return response."""
    messages = [
        SystemMessage(content="You are a helpful assistant."),
        *state["messages"]
    ]
    response = model.invoke(messages)
    return {"messages": [response]}


def call_tools(state: State) -> dict:
    """Execute tool calls from the last message."""
    from langchain.messages import ToolMessage

    last_message = state["messages"][-1]
    results = []

    for tool_call in last_message.tool_calls:
        tool_fn = tools_by_name[tool_call["name"]]
        result = tool_fn.invoke(tool_call["args"])
        results.append(
            ToolMessage(content=str(result), tool_call_id=tool_call["id"])
        )

    return {"messages": results}


# 5. Define routing
def should_continue(state: State) -> Literal["tools", "__end__"]:
    """Route to tools or end based on last message."""
    last_message = state["messages"][-1]
    if last_message.tool_calls:
        return "tools"
    return END


# 6. Build and compile graph
builder = StateGraph(State)
builder.add_node("model", call_model)
builder.add_node("tools", call_tools)
builder.add_edge(START, "model")
builder.add_conditional_edges("model", should_continue, ["tools", END])
builder.add_edge("tools", "model")

# Compile with checkpointer for memory/HITL
graph = builder.compile(checkpointer=InMemorySaver())


def main():
    # Use thread_id for conversation persistence
    config = {"configurable": {"thread_id": "user-123"}}

    result = graph.invoke(
        {"messages": [HumanMessage(content="Hello!")]},
        config=config
    )

    for msg in result["messages"]:
        print(f"{msg.type}: {msg.content}")


if __name__ == "__main__":
    main()

Read the full file on GitHub · 217 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 217 lines · 13 tokens per session scan A 09f5598f35bc

Subscribe to this mod's changes

new-agent is a command published in the GitHub repository Codeblockz/langchain-community-plugin (3 stars, last pushed 7mo ago), licensed Apache-2.0. It adds 13 tokens to every session and 1,237 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.