Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.swarms.world/llms.txt

Use this file to discover all available pages before exploring further.

The GKP Agent enhances its reasoning by generating relevant knowledge before answering queries. This approach, inspired by Liu et al. 2022, is particularly effective for tasks requiring commonsense reasoning and factual information. The agent consists of three main components:
  1. Knowledge Generator — Creates relevant factual information
  2. Reasoner — Uses generated knowledge to form answers
  3. Coordinator — Synthesizes multiple reasoning paths into a final answer

Architecture

API Reference

GKPAgent

ParameterTypeDefaultDescription
agent_namestr"gkp-agent"Name identifier for the agent
model_namestr"openai/o1"LLM model to use for all components
num_knowledge_itemsint6Number of knowledge snippets to generate per query
MethodParametersReturns
process(query)query: strDict[str, Any] — full processing results
run(queries, detailed_output?)queries: List[str], detailed_output: boolUnion[List[str], List[Dict[str, Any]]]

KnowledgeGenerator

ParameterTypeDefaultDescription
agent_namestr"knowledge-generator"Name identifier
model_namestr"openai/o1"Model for knowledge generation
num_knowledge_itemsint2Number of knowledge items to generate per query
MethodParametersReturns
generate_knowledge(query)query: strList[str] — generated knowledge statements

Reasoner

ParameterTypeDefaultDescription
agent_namestr"knowledge-reasoner"Name identifier
model_namestr"openai/o1"Model for reasoning
MethodParametersReturns
reason_and_answer(query, knowledge)query: str, knowledge: strDict[str, str] — explanation, confidence, answer

Example

from swarms.agents.gkp_agent import GKPAgent

agent = GKPAgent(
    agent_name="gkp-agent",
    model_name="claude-sonnet-4-6",
    num_knowledge_items=6,
)

queries = [
    "What are the implications of quantum entanglement on information theory?",
]

results = agent.run(queries)

for i, result in enumerate(results):
    print(f"\nQuery {i+1}: {queries[i]}")
    print(f"Answer: {result}")

Best Practices

  1. Knowledge Generation: Set appropriate number of knowledge items based on query complexity
  2. Reasoning Process: Ensure diverse reasoning paths for complex queries. Validate confidence levels.
  3. Coordination: Review coordination logic for complex scenarios. Validate final answers against source knowledge.

Performance Considerations

  • Processing time increases with number of knowledge items
  • Complex queries may require more knowledge items
  • Consider caching frequently used knowledge
  • Monitor token usage for cost optimization