Skip to main content

LangChain integration for SkillBroker - Access expert knowledge in your AI agents

Project description

SkillBroker LangChain Integration

Add expert knowledge to your LangChain agents with SkillBroker - the marketplace where AI agents pay for human expertise.

Installation

pip install skillbroker-langchain

Quick Start

Using a Specific Skill

from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from skillbroker_langchain import SkillBrokerTool

# Create a tool for a specific skill
tax_advisor = SkillBrokerTool(
    skill_id="freelancer-tax-advisor",
    name="tax_advisor",
    description="Get expert advice on freelancer and self-employment tax questions"
)

# Set up your agent
llm = ChatOpenAI(model="gpt-4")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant. Use the tax_advisor tool for tax questions."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_openai_tools_agent(llm, [tax_advisor], prompt)
executor = AgentExecutor(agent=agent, tools=[tax_advisor])

# Ask a question
result = executor.invoke({"input": "Can I deduct my home office as a freelancer?"})
print(result["output"])

Searching for Skills

from skillbroker_langchain import SkillBrokerSearchTool

# Create a search tool
search = SkillBrokerSearchTool()

# Find relevant skills
results = search.invoke({"query": "financial planning"})
print(results)

Dynamic Expert Tool

Let the agent automatically find and use the right skill:

from skillbroker_langchain import SkillBrokerDynamicTool

# This tool can handle any domain question
expert = SkillBrokerDynamicTool(
    name="expert_knowledge",
    description="Get expert knowledge on any specialized topic"
)

# The tool will search for and invoke the best matching skill
result = expert.invoke({"query": "What's the best way to structure a holding company?"})

Using the Client Directly

from skillbroker_langchain import SkillBrokerClient

client = SkillBrokerClient()

# Get registry info
info = client.get_registry_info()
print(f"Total skills available: {info['stats']['totalSkills']}")

# Search for skills
results = client.search("machine learning")
for skill in results.skills:
    print(f"- {skill.name}: {skill.description}")

# Get top-rated skills
top_skills = client.get_top_skills(limit=5)

# Invoke a skill directly
response = client.invoke("skill-id", "Your question here")
print(response.response)

Configuration

Environment Variables

# Optional: Override the API URL (defaults to https://api.skillbroker.io)
export SKILLBROKER_API_URL="https://api.skillbroker.io"

# Optional: API key for authenticated requests
export SKILLBROKER_API_KEY="your-api-key"

Programmatic Configuration

from skillbroker_langchain import SkillBrokerClient, SkillBrokerTool

# Configure client
client = SkillBrokerClient(
    api_url="https://api.skillbroker.io",
    api_key="your-api-key",
    timeout=30,
)

# Configure tools
tool = SkillBrokerTool(
    skill_id="my-skill",
    api_url="https://api.skillbroker.io",
    api_key="your-api-key",
)

Available Tools

Tool Description
SkillBrokerTool Invoke a specific skill by ID
SkillBrokerSearchTool Search the marketplace for skills
SkillBrokerDynamicTool Automatically find and invoke the best skill

Examples

Multi-Tool Agent

from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_openai import ChatOpenAI
from skillbroker_langchain import SkillBrokerTool, SkillBrokerSearchTool

# Create multiple skill tools
tax_tool = SkillBrokerTool(
    skill_id="freelancer-tax-advisor",
    name="tax_advisor",
    description="Tax advice for freelancers"
)

legal_tool = SkillBrokerTool(
    skill_id="contract-reviewer",
    name="contract_advisor",
    description="Contract and legal document review"
)

search_tool = SkillBrokerSearchTool()

# Use all tools in your agent
tools = [tax_tool, legal_tool, search_tool]
agent = create_openai_tools_agent(llm, tools, prompt)

With CrewAI

from crewai import Agent, Task, Crew
from skillbroker_langchain import SkillBrokerTool

# Create SkillBroker tools
tax_tool = SkillBrokerTool(
    skill_id="freelancer-tax-advisor",
    name="tax_advisor",
    description="Expert tax advice"
)

# Create a CrewAI agent with the tool
tax_agent = Agent(
    role="Tax Consultant",
    goal="Provide accurate tax advice",
    backstory="You are an expert tax consultant.",
    tools=[tax_tool],
)

task = Task(
    description="Help the user understand their tax obligations",
    agent=tax_agent,
)

crew = Crew(agents=[tax_agent], tasks=[task])
result = crew.kickoff()

API Reference

SkillBrokerClient

client = SkillBrokerClient(api_url=None, api_key=None, timeout=30)

# Methods
client.get_registry_info() -> dict
client.search(query=None, category=None, limit=20) -> SearchResult
client.get_skill(skill_id) -> Skill
client.invoke(skill_id, query, context=None) -> SkillResponse
client.get_categories() -> list
client.get_top_skills(limit=10, category=None) -> list[Skill]
client.get_recommendations(task_description, limit=5) -> list[Skill]

Models

from skillbroker_langchain import Skill, SkillResponse, SkillQuery

# Skill attributes
skill.id
skill.name
skill.description
skill.category
skill.pricing
skill.stats
skill.quality

# Response attributes
response.success
response.response
response.skill_id
response.tokens_used
response.cost

Support

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skillbroker_langchain-0.1.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skillbroker_langchain-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file skillbroker_langchain-0.1.0.tar.gz.

File metadata

  • Download URL: skillbroker_langchain-0.1.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for skillbroker_langchain-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3f067adcb6348bd596c182bbfc5ef4ec79c024872af173069fc3c1e9ee58fa97
MD5 20aaa49fe83567e101ec4cf1a4a92ac8
BLAKE2b-256 7d95bab214722110b71f864859a746c6f5c422e5356c7e851bd7d003f8d9a357

See more details on using hashes here.

File details

Details for the file skillbroker_langchain-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for skillbroker_langchain-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d6d1c3fd29f014979f8dea33dc0db58cc411dc949e1a86c48501cd099434457
MD5 640013b685fac144722745cb72d66f06
BLAKE2b-256 70b7ef9de6a06c14d5b03a7cecfc8ce38072c09ad851f59a6587bde2061f38e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page