lightninglabs / lightninglabs/LangChainBitcoin

feature: use tools schema to provide more context for complex function calls

Open
#1 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
143
Forks
19
PR merge metrics
No merged PRs in 30d

Description

Today we create a series of wrappers around the base set of lnd gRPC API endpoints. This works well for simple calls like `addinvoice` that have simple inputs, but for other calls, we want to be able to give more context to the agent in form of a better input schema.

Some examples of this are here: https://python.langchain.com/docs/modules/agents/tools/how_to/tool_input_validation

As an example, consider the `new_address` tool. The input is actually an enum of the address type with the following values: `WITNESS_PUBKEY_HASH`, `TAPROOT_PUBKEY`, etc, etc. We can define a more structred input that looks something like:
```python
class AddrTypes(Enum):
TAPROOT_PUBKEY = 0
WITNESS_PUBKEY_HASH = 1

class NewAddrSchema(BaseModel):
addr_type: AddrTypes = Field("the type of address to create")
```

Then each time we use the `@tool` decorator, we also pass the schema for the input like `@tool(args_schema=NewAddrSchema`).

For other calls that need more arguments, like finding a route on LN to a dest, then we can use a similar pattern to be able to profile few-shot examples for each of the fields, and also validate them.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the wrappers around the lnd gRPC endpoints, especially the new_address tool, and review how the @tool decorator is currently used. Compare the proposed schemas with the linked LangChain tool-input validation guidance. Done means complex tools expose structured inputs with enum values, field context or examples, and validation, including calls that need multiple arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.