Skip to content

.getResponse()


AgentForceAgent Execution Method Asynchronous

Execute the agent and return the raw LLM response as a string. This is a execution method that triggers agent execution and returns only the response content - not the agent instance for chaining.

getResponse(): Promise<string>

This method takes no parameters.

Returns a Promise<string> containing the raw LLM response.

import { AgentForceAgent } from '@agentforce/adk';
const agent = new AgentForceAgent({
name: "QuestionAgent"
})
.useLLM("ollama", "gemma3:4b")
.prompt("What is the capital of France?");
const response = await agent.getResponse();
console.log(response); // "Paris is the capital of France."
import { AgentForceAgent, type AgentConfig } from '@agentforce/adk';
const config: AgentConfig = {
name: "DebugExclusionsTest",
tools: ["fs_find_files"]
};
const DebugExclusionsTest = new AgentForceAgent(config)
.useLLM("ollama", "qwen3-coder-tool", {
appendToolResults: true,
maxToolRounds: 2
})
.systemPrompt("You are a debugging assistant. Show me the exclusions and found files data exactly as provided by the tool.")
.prompt("Search for all .md files and show me the raw exclusions list that was applied");
const response = await DebugExclusionsTest.getResponse();
console.log("Debug Output:");
console.log(response);
// Get response and process it
const agent = new AgentForceAgent({ name: "ProcessingAgent" })
.systemPrompt("Return your response as valid JSON")
.prompt("List 3 programming languages with their main use cases");
const response = await agent.getResponse();
try {
// Try to parse as JSON
const data = JSON.parse(response);
console.log("Structured data:", data);
} catch (error) {
// Handle as plain text
console.log("Plain text response:", response);
}
class ResponseProcessor {
static async getAndProcess(agent: AgentForceAgent) {
const response = await agent.getResponse();
return {
raw: response,
wordCount: response.split(/\s+/).length,
lines: response.split('\n').length,
isEmpty: response.trim().length === 0,
containsCode: /```/.test(response),
timestamp: new Date().toISOString()
};
}
}
// Usage
const agent = new AgentForceAgent({ name: "ProcessedAgent" })
.prompt("Write a short poem about coding");
const result = await ResponseProcessor.getAndProcess(agent);
console.log("Response metadata:", result);

Simple Q&A

Best for: Direct questions, explanations, definitions

Pattern: Configure → Prompt → GetResponse

Example: “What is Docker?” → Get explanation text

Content Generation

Best for: Blog posts, documentation, creative writing

Pattern: System prompt for style → Content request → GetResponse

Example: Generate marketing copy or technical documentation

Tool Output Analysis

Best for: Debugging tool behavior, analyzing tool results

Pattern: Tools enabled → Analysis prompt → GetResponse

Example: File system analysis with fs_find_files tool

Raw Response Debugging

Best for: Debugging agent behavior, testing prompts

Pattern: Debug system prompt → Test prompt → GetResponse

Example: Testing how the agent responds to specific inputs

// Clear, specific prompts
const response = await agent
.systemPrompt("You are a technical writer")
.prompt("Explain REST APIs in 200 words for beginners")
.getResponse();
// Handle responses appropriately
const result = await agent.getResponse();
if (result.startsWith("Error:")) {
console.error("Agent encountered an error:", result);
} else {
console.log("Success:", result);
}
// Process response content when needed
const jsonResponse = await agent.getResponse();
try {
const data = JSON.parse(jsonResponse);
// Work with structured data
} catch {
// Handle as plain text
}
// ❌ Trying to chain after getResponse()
const result = await agent
.prompt("Hello")
.getResponse()
.prompt("Follow up"); // Error: getResponse() is terminal
// ❌ Not handling async properly
const response = agent.getResponse(); // Missing await
console.log(response); // Logs Promise object
// ❌ Not handling potential errors
const response = await agent.getResponse(); // Could throw or return error message
// Should check if response indicates an error
// Error handling is built-in
const agent = new AgentForceAgent({
name: "ErrorProneAgent",
tools: ["nonexistent_tool"] // This will cause an error
})
.prompt("Use the nonexistent tool");
try {
const response = await agent.getResponse();
// If execution fails, the method will return the error message from chat history
console.log("Response (may contain error):", response);
} catch (error) {
// Only throws if no error message is found in chat history
console.error("Execution failed:", error.message);
}